Android 重启广播接收器后未运行

标签 android service alarmmanager android-reboot

我使用了这个权限:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

接收者是:

<receiver android:name=".auth.NotificationBroadcast" android:enabled="true" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

代码中的接收者是:

@Override
    public void onReceive(Context context, Intent intent) {

        System.out.println("BroadcastReceiverBroadcast--------------------ReceiverBroadcastReceiverBroadcastReceiver----------------BroadcastReceiver");

        if (intent != null) {
            String action = intent.getAction();

        switch (action) {
            case Intent.ACTION_BOOT_COMPLETED:
                System.out.println("Called on REBOOT");
                // start a new service and repeat using alarm manager

                break;
            default:
                break;
        }
    }
}

重新启动后,它仍然没有在 Lollipop 中被调用,但在棉花糖上它正在运行。

最佳答案

尝试将此行放入接收者的 intent-filter 中。

<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />

如果您的应用程序安装在 SD 卡上,您应该注册它以获取 android.intent.action.BOOT_COMPLETED 事件。

更新:由于您的应用正在使用闹钟服务,因此不应将其安装在外部存储设备上。引用:http://developer.android.com/guide/topics/data/install-location.html

关于Android 重启广播接收器后未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39555388/

相关文章:

java - 使用 Android 通过 OAuth1 调用 Open Bank Project

java - 当设备处于 sleep 状态时在后台运行广播接收器?

android - 在 Android sdk 警报管理器中的选定日期重复计划任务

android - 在 android 的 Alarm Manager 中使用 intent extras 传递值

android - 是否可以通过 wifi 在 2 个 android 设备之间交换消息?

android - 在 Android 的 ActionBar 中显示图标和标题

java - 谷歌 OAuth : how to use a refresh token?

service - PostgreSQL 9.2.4 (Windows 7) - 服务无法启动, "could not load pg_hba.conf"

angular - 如何在 Angular 中使用 mergeWith 与主题

java - 无法在 Android 中使用 AlarmManager 停止服务