gpt4 book ai didi

android - 当我的应用程序崩溃时如何设置自定义对话框?

转载 作者:太空狗 更新时间:2023-10-29 13:56:29 25 4
gpt4 key购买 nike

我在我的应用程序中使用 ACRA 4.9.0。我只想在我的应用程序崩溃时向用户显示对话框。

这是我当前的代码:

public class App extends MultiDexApplication {

@Override
public void onCreate() {
ConfigurationBuilder config = new ConfigurationBuilder(this);
config.setMailTo("mailto@gmail.com");
config.setResDialogIcon(android.R.drawable.ic_dialog_info);
config.setResDialogText(R.string.crash_dialog_text);
config.setResDialogTitle(R.string.crash_dialog_title);
config.setResDialogCommentPrompt(R.string.crash_dialog_comment_prompt);
config.setResDialogOkToast(R.string.crash_dialog_ok_toast);
config.setMode(ReportingInteractionMode.DIALOG);

try{
config.setMode(ReportingInteractionMode.DIALOG);
} catch (Exception e) {
e.printStackTrace();
return;
}

ACRA.init(this, config);
super.onCreate();
Instance = this;
applicationHandler = new Handler(getInstance().getMainLooper());
}

最佳答案

完整的工作演示

应用类

@ReportsCrashes(formUri = "http://yourserver.com/yourscript",
mode = ReportingInteractionMode.DIALOG,
resToastText = R.string.app_name,
resDialogText = R.string.app_name,
resDialogIcon = android.R.drawable.ic_dialog_info,
resDialogTitle = R.string.app_name,
resDialogCommentPrompt = R.string.app_name,
resDialogEmailPrompt = R.string.app_name,
resDialogOkToast = R.string.app_name,
resDialogTheme = R.style.AppTheme_Dialog)

public class App extends Application {

private Context context;

@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
ACRA.init(this);
}
}

主 Activity

public class MainActivity extends AppCompatActivity {
Context context;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;

EditText number = (EditText) findViewById(R.id.foodName);
number.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int a = 0 / 0;
}
});
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/base"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="@color/white"
android:orientation="horizontal"
android:weightSum="10">


<EditText
android:id="@+id/foodName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="64dp"
android:layout_marginRight="64dp"
android:hint="Food name"
android:inputType="textCapWords"
android:textColor="@color/colorPrimaryDark"
android:textColorHint="@color/colorPrimaryDark"
android:textSize="32sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

</RelativeLayout>

对话框:

enter image description here

关于android - 当我的应用程序崩溃时如何设置自定义对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39248000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com