BOOT RECEIVER过滤包装

问题描述 投票:1回答:1

我一直在寻找有关启动接收器的一些答案,但没有解决我的问题。我在代码中添加了所有解决方案。

我想接收在Android OREO上完成的启动,到目前为止该设备无法正常工作。这是完整的实现

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

    //inside application
    <receiver
        android:name="com.anb.lucem.reminder.services.BootReceiver" 
        android:exported="true"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

boot receiver.Java

public class BootReceiver extends BroadcastReceiver {

    private String TAG = "com.lucemanb.reminderapp.boot";

    public void onReceive(final Context context, Intent intent) {

        Log.d(TAG, "Boot Completed");
    }
}

这在API 26下运行良好,但Oreo似乎有不同的方法

    09-10 16:45:55.792 848-873/? D/AppLockLoader: isAppLocked: packageName=com.anb.lucem.reminder, isLocked=false
09-10 16:45:57.860 657-951/? D/ProcessManager.AS: *** Skip {com.anb.lucem.reminder} to receive broadcast.
09-10 16:45:57.860 657-951/? D/BroadcastQueue: *** Not launch app com.anb.lucem.reminder/10130 for broadcast Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } from null/1000.(AutoStart limited)

有什么事我做错了吗?

android receiver
1个回答
1
投票

此代码在Android 8.1或更低版本中经过测试和使用

表现:

       <receiver
            android:name=".BootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

类:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

    public class BootReceiver extends BroadcastReceiver {

        private static final String ACTION_QUICK_BOOT = "android.intent.action.QUICKBOOT_POWERON";

        @Override
        public void onReceive(Context context, Intent intent) {
            if(null != intent) {
                final String action = intent.getAction();
                if (Intent.ACTION_BOOT_COMPLETED.equals(action) || ACTION_QUICK_BOOT.equals(action)) {

                    // here do what you want to do on boot
                }
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.