自定义广播8.0收不到推送

自定义广播8.0收不到推送问题,报错:

Background execution not allowed: receiving Intent

解决办法有两个

1.自定义广播

在此感谢 一叶漂舟 大佬给的解决办法。

引用自己声明的权限 ,可不引用
<uses-permission android:name="com.eestorm.cefsdk.receiver" />

<permission//声明自定义权限
    android:name="com.eestorm.cefsdk.receiver"
    android:protectionLevel="signature"/>


<receiver android:name=".TestPush"
android:permission="com.eestorm.cefsdk.receiver"
android:exported="true">
<intent-filter>
<action android:name="xxx.xxx"/
<category android:name="${applicationId}" />
</intent-filter>
</receiver>


context.sendBroadcast(intent,"com.eestorm.cefsdk.receiver");

2.setComponent

`
intent.setComponent(new ComponentName(“package name”,”class name”));

`

/**
* Create a new component identifier.
*
* @param pkg The name of the package that the component exists in. Can
* not be null.
* @param cls The name of the class inside of <var>pkg</var> that
* implements the component. Can not be null.
*/
public ComponentName(@NonNull String pkg, @NonNull String cls) {
if (pkg == null) throw new NullPointerException("package name is null");
if (cls == null) throw new NullPointerException("class name is null");
mPackage = pkg;
mClass = cls;
}

package name:项目包名
class name:具体的receiver的全类名。

两种方法亲测有效。

猜你喜欢

转载自blog.csdn.net/MyheartMylove/article/details/80970772
今日推荐