如果应用崩溃,我的应用会使用ACRA发送无声通知。
official documentation显示了如何使用XML设置用户电子邮件,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
首选项的方式与下面接受的答案中显示的方式类似。
答案 0 :(得分:0)
文档说明你可以通过SharedPreferences
:
getSharedPreferences().edit().putString( "acra.user.email", "your@email.com" ).commit();
应该做的伎俩。我没有测试过,因为我没有看到在我的设置中在运行时设置电子邮件地址的用处。