我有以下 Reciever,我在设备启动时遇到应用程序崩溃。
由于它发生在启动时,我无法通过 eclipse 附加调试,也无法在 logcat 中看到任何内容。
您建议我如何查看导致崩溃的错误?
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
if (intent != null) {
String action = intent.getAction();
if (action != null) {
if (action.equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// GeoPushService geoPs = new GeoPushService();
ZoomerLocationService locService = new ZoomerLocationService();
locService.startService(new Intent());
// Log.d("receiver","action is: boot");
}
}
}
}
}
我试过添加这个 try-catch
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
if (intent != null) {
String action = intent.getAction();
try {
if (action != null) {
if (action.equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// GeoPushService geoPs = new GeoPushService();
ZoomerLocationService locService = new ZoomerLocationService();
locService.startService(new Intent());
// Log.d("receiver","action is: boot");
}
}
} catch (Exception ex) {
Log.e(MyLogger.TAG, ex.getStackTrace().toString());
}
}
}
}
但是没用
我已尝试发送 BOOT_COMPLETE Intent ,但权限被拒绝
最佳答案
您可以在命令行中使用 ADB 在设备启动时记录 logcat。
http://developer.android.com/tools/help/logcat.html
http://www.herongyang.com/Android/Debug-adb-logcat-Command-Option-Log-Buffer.html
确保增加命令窗口可以显示的数据量,或者使用选项将日志保存到文件。
使用此方法,您可能会在启动日志中看到崩溃。
编辑:我已经试过了,这是可能的,这应该对你有用
关于java - 如何调试引导接收器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23931452/