我想發送/data/anr/traces.txt如果應用程序曾經崩潰,但問題是我怎麼知道我的應用程序崩潰之前。抓住或檢測ANR異常
File file = new File("/data/anr/traces.txt");
if (file.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("subject", file.getName());
intent.putExtra("body", "...");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
if (file.getName().endsWith(".gz")) {
intent.setType("application/x-gzip");
} else if (file.getName().endsWith(".txt")) {
intent.setType("text/plain");
} else {
intent.setType("application/octet-stream");
}
// ? Can I send it without permission?
startActivity(intent);
}
順便說一句,ACRA崩潰報告與traces.txt相同嗎? – thecr0w
@ thecr0w:此鏈接 - https://github.com/SalomonBrys/ANR-WatchDog,也有助於檢測Android應用程序中的ANR – Basher51