如何在安卓中更改崩溃消息(如果可能)

  • 本文关键字:消息 如果 崩溃 android
  • 更新时间 :
  • 英文 :


我想知道是否可以更改安卓的崩溃消息?("不幸的是,应用程序已停止"(我没有找到任何说你可以的东西(我认为你不能(,我只是通过在这里询问来确保。

谢谢

您无法按照 @Nuno Gomes 的规定更改系统消息,但您可以禁止显示原始消息并自行显示消息或启动某些活动。

您可以定义一个异常处理程序,用于捕获应用程序类中所有未捕获的异常,并从那里显示一个消息框

public class MyApp extends Application  implements Thread.UncaughtExceptionHandler {
private Thread.UncaughtExceptionHandler mPreviousUncaughtExceptionHandler;
@Override public void onCreate() {
super.onCreate();
mPreviousUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
try {
// Do your stuff with the exception
Log.e(Global.LOG_CONTEXT,"LogCat.uncaughtException " + ex, ex);
// show user defined messagebox
} catch (Exception e) {
/* Ignore */
} finally {
// uncomment this to let Android show the default error dialog
// mPreviousUncaughtExceptionHandler.uncaughtException(thread, ex);
}
}
}

必须在清单中声明应用

<manifest ...>
...
<application
android:name=".MyApp" ...>
</application>
</manifest> 

在我的 android-4.4 上,我使用此代码编写一个 chrash 日志文件

该消息是系统消息,它超出了应用程序范围,因此不,您无法更改它

最新更新