android8.0以后的系统,为了提高系统的性能,所以对第三方app注册的静态广播,不做处理,该怎么解决这问题呢,下面直接分享代码:
Intent poweronff = new Intent("com.bob.intent.action.POWER_ON_OFF_TIMER");//自定义action
poweronff.putExtra("enable",true);
poweronff.putExtra("timeon",poweron);
poweronff.putExtra("timeoff",poweroff);
poweronff.setComponent(new ComponentName("com.android.tv.settings.receiver","com.android.tv.settings.receiver.PoweronoffBroadcastReceiver"));//第一个参数包名,第二个参数广播类
mContext.sendBroadcast(poweronff);
2.注册广播类
<receiver android:name=".PoweronoffBroadcastReceiver"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="com.bob.intent.action.POWER_ON_OFF_TIMER"/>
</intent-filter>
</receiver>