Android - 如何以编程方式在 Acra 崩溃报告中设置 USER_EMAIL?
Android - How to programmatically set USER_EMAIL in Acra crash report?
我的应用程序使用 ACRA 在应用程序崩溃时发送静默通知。
official documentation shows how to set the user email in XML and this SO question显示了如何通过注释设置它,但是如何在代码中设置用户电子邮件地址?
假设我已经开始朝着正确的方向前进,这就是我所得到的...
ACRA.init(this);
ACRAConfiguration acraConfig = ACRA.getConfig();
//acraConfig.howToSetUserEmail???
更新
感谢 323go 的帮助,这是工作代码:
import org.acra.*;
import org.acra.annotation.ReportsCrashes;
import android.app.Application;
import android.content.Context;
@ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "http://example.com/crash-reports/my-script-which-emails-me-the-acra-data.php",
sharedPreferencesName = "THE_NAME_OF_MY_SHARED_PREFS_FILE",
sharedPreferencesMode = Context.MODE_PRIVATE
)
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
然后,在我的应用程序的其他地方,我以类似的方式设置 acra.user.email
首选项,如下面已接受的答案所示。
文档说你可以通过 SharedPreferences
:
getSharedPreferences().edit().putString( "acra.user.email", "your@email.com" ).commit();
应该可以解决问题。我还没有测试过,因为我没有看到在我的设置中 运行-time 设置电子邮件地址有多大用处。
我的应用程序使用 ACRA 在应用程序崩溃时发送静默通知。
official documentation shows how to set the user email in XML and this SO question显示了如何通过注释设置它,但是如何在代码中设置用户电子邮件地址?
假设我已经开始朝着正确的方向前进,这就是我所得到的...
ACRA.init(this);
ACRAConfiguration acraConfig = ACRA.getConfig();
//acraConfig.howToSetUserEmail???
更新
感谢 323go 的帮助,这是工作代码:
import org.acra.*;
import org.acra.annotation.ReportsCrashes;
import android.app.Application;
import android.content.Context;
@ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "http://example.com/crash-reports/my-script-which-emails-me-the-acra-data.php",
sharedPreferencesName = "THE_NAME_OF_MY_SHARED_PREFS_FILE",
sharedPreferencesMode = Context.MODE_PRIVATE
)
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
然后,在我的应用程序的其他地方,我以类似的方式设置 acra.user.email
首选项,如下面已接受的答案所示。
文档说你可以通过 SharedPreferences
:
getSharedPreferences().edit().putString( "acra.user.email", "your@email.com" ).commit();
应该可以解决问题。我还没有测试过,因为我没有看到在我的设置中 运行-time 设置电子邮件地址有多大用处。