引导完成的广泛投射未在Oreo及更高版本的设备中显示

时间:2018-12-20 11:20:29

标签: android broadcast boot bootcompleted

我的引导广播不适用于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");
    }
}

0 个答案:

没有答案