Receiver stopped receiving in Oreo

让人想犯罪 __ 提交于 2019-11-30 10:26:07

Since Android Oreo, receivers must be registered in runtime using context.registerReceiver(receiver, intentFilter); to receive implicit intents

You can still receive explicit intents and some special implicit actions, as boot_completed or locale_changed for example

More information at https://developer.android.com/about/versions/oreo/background.html#broadcasts

create your intent than pass in method

 sendImplicitBroadcast(this,new Intent(IntentActions.ACTION_APP_CREATE));

Static Method

public static void sendImplicitBroadcast(Context ctxt, Intent i) {
    PackageManager pm=ctxt.getPackageManager();
    List<ResolveInfo> matches=pm.queryBroadcastReceivers(i, 0);

    for (ResolveInfo resolveInfo : matches) {
        Intent explicit=new Intent(i);
        ComponentName cn=
                new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
                        resolveInfo.activityInfo.name);

        explicit.setComponent(cn);
        ctxt.sendBroadcast(explicit);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!