Android 在应用程序崩溃时联系webservice
我希望我的Android应用程序通过使用(POST)Web服务将stacktrace发送到我的后端应用程序来处理未捕获的异常。为此,我在父活动中设置了一个UncaughtExceptionHandler:Android 在应用程序崩溃时联系webservice,android,web-services,uncaughtexceptionhandler,Android,Web Services,Uncaughtexceptionhandler,我希望我的Android应用程序通过使用(POST)Web服务将stacktrace发送到我的后端应用程序来处理未捕获的异常。为此,我在父活动中设置了一个UncaughtExceptionHandler: Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this)); 在CustomExceptionHandler中,我重写了uncaughtException方法: @Override public vo
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
在CustomExceptionHandler中,我重写了uncaughtException方法:
@Override
public void uncaughtException(Thread thread, Throwable ex) {
HttpURLConnection connection = null;
try {
URL url = new URL("http://mywebserviceurl.com?message=justatest");
connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
} catch (Exception e) {
//Handle crash
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
为了测试这一点,我强制我的应用程序崩溃:
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
throw new RuntimeException("");
}
}, 2500);
但是我的网络服务没有联系。当我在try子句的第二行设置断点时,调试器似乎很快就到达了这一行,然后程序和调试器就退出了。我还尝试创建一个新线程来处理webservice调用,尝试使用AsyncTasks,但行为保持不变:从未联系过我的webservice。出什么事了
谢谢。ACRA库具有您需要的功能我想谢谢,我会检查它,当我发现它有用时,我会带着更多详细信息返回此库。也许您会更成功地将Stacktrace写入文件,并在应用程序上检查startACRA库具有您需要的功能我想谢谢,当我发现它有用时,我会检查它,并返回到更多细节。也许你会更成功地将Stacktrace写入文件,并在应用程序启动时检查它