java - 如何调试引导接收器?

标签 java android broadcastreceiver

我有以下 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/

相关文章:

android - 将 tess-two(Tesseract Tools for Android)库集成到 Android 工作室并构建 ndk

java - Android 中自动创建尺寸

android - 为什么 Messenger 应用程序会在应用程序强制停止时收到消息?

java - 输入字符串未知时的字符串分割(Java Android 短信分割转发)

java - 使用 JAVA API 的 Rally 项目的修订历史

java - 从 ARGB 位图加载 BufferedImage

java - 没有最终参数的函数,其中包括 Runnable()

java - 在大型机中使用 JMS 从 java 连接到 MQ

android - 新手字符串错误

java - BroadcastReceiver 未收到 ACTION_SCREEN_OFF Intent