简体   繁体   English

如何调试启动接收器?

[英]how to debug boot receiver?

I have the following Reciever and I get an app crash on device boot. 我有以下接收者,设备启动时出现应用程序崩溃。

Since it happens on boot I cannot attach the debug via eclipse nor see anything in the logcat. 由于它是在启动时发生的,因此我无法通过eclipse附加调试,也无法在logcat中看到任何内容。

How would you suggest for me to see the error causing the crash? 您如何建议我查看导致崩溃的错误?

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");
                    }
                }

        }
    }
}

I have tried adding this try-catch 我尝试添加此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());
            }
        }
    }
}

but it didn't help 但这没有帮助

I have tried to send BOOT_COMPLETE intent and i got permissions denial 我尝试发送BOOT_COMPLETE意向,但我拒绝了权限

You might be able to use ADB in a command line to record the logcat when your device is booting up. 您可以在设备启动时在命令行中使用ADB来记录logcat。

http://developer.android.com/tools/help/logcat.html http://developer.android.com/tools/help/logcat.html

http://www.herongyang.com/Android/Debug-adb-logcat-Command-Option-Log-Buffer.html http://www.herongyang.com/Android/Debug-adb-logcat-Command-Option-Log-Buffer.html

Make sure to increase the amount of data the command window can display or else use the options to save the log to a file. 确保增加命令窗口可以显示的数据量,否则请使用选项将日志保存到文件。

Using this method you might be able to see the crash in the log on startup. 使用此方法,您可能能够在启动日志中看到崩溃。

EDIT: I have tried this and it is possible, this should work for you 编辑:我已经尝试过,并且有可能,这应该为您工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM