自定义广播8.0收不到推送

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

Background execution not allowed: receiving Intent

解决办法有两个

1.自定义广播

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

引用自己声明的权限 ,可不引用




android:permission="com.eestorm.cefsdk.receiver"
android:exported="true">





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 pkg 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的全类名。

两种方法亲测有效。

你可能感兴趣的:(AndroidSDK那些事儿)