首页 > 解决方案 > Boot_Completed 广播未在应用程序中接收

问题描述

我正在测试一个非常基本的应用程序,用于Boot_Completed在设备重启时进行广播。我正在测试应用程序android 10 OPPO device 以下是我的代码

清单.xml

  <receiver android:name=".SampleBootReceiver" android:enabled="true" android:exported="true">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
            <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
            <!--For HTC devices-->
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

SampleBootReceiver.java

public class SampleBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.e("MyApp", " Boot completed fired");
    Toast.makeText(context, "fired " , Toast.LENGTH_LONG).show();
    if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
        Log.e("MyApp", "matches intent");
    }
}
}

我的应用程序在设备重启时没有收到Boot_Completed广播。

注意- 如果我在设备重新启动后手动启动应用程序,那么我会在我的应用程序中广播并且能够在 logcat 中看到日志。但是当我在设备重启后没有启动应用程序时,logcat 中没有任何内容。

我什至尝试过showing toast接收广播,没有任何反应。

请建议!

标签: javaandroidbroadcastreceiverbootcompleted

解决方案


推荐阅读