我的引导广播不适用于Oreo及更高版本的API。
我已经在Oreo API下尝试了此代码,使其工作正常(广播运行),实际上我想先在启动完成时运行该服务,我想测试是否在启动手机时触发了广播。
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".BroadCastRecieverTostartClipboard"
android:enabled="true"
android:directBootAware="true"
android:exported="true">
<intent-filter>
<!-- For pre-N devices -->
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<!--for above N devices -->
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
public class BroadCastRecieverTostartClipboard extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"outside ",Toast.LENGTH_SHORT).show();
Log.i("mylog","on recieve broadcast To StartClipboard before booted completed");
}
}