Android Broadcast Receiver(启动完成)在Realme,MI和Oppo手机上无法正常工作

时间:2019-11-13 07:55:24

标签: android android-studio broadcastreceiver bootcompleted

我为我的应用程序创建了One Boot Completed BroadCast接收器。当应用程序安装在Realme,MI,Oppo设备上或重新启动设备后,它无法正常工作,但是当我在三星,MOTO和其他设备上安装该应用程序时,它运行正常。

我在Google上进行了搜索,发现我确实明确调用了BroadCast Receiver所需的解决方案,但是仍然无法正常工作。

下面是我实现的代码

AndroidManifest.xml

        <receiver
            android:name=".BootCompletReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter android:priority="999">
                <action android:name="YouWillNeverKillMe" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

BootCompletReceiver.java

public class BootCompletReceiver extends BroadcastReceiver {
    Context mContext;
    Intent mIntent;

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

        mContext = context;
        mIntent = intent;
        Log.d("gd_Switch on receiver", intent.getExtras() + "");

        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Toast.makeText(mContext,"Device Started Successfully",Toast.LENGTH_LONG).show();
        }
    }
}

请帮助我,最近两周我一直坚持下去,但仍然没有解决办法

0 个答案:

没有答案