Receiver stopped receiving in Oreo

前端 未结 2 1070
無奈伤痛
無奈伤痛 2021-01-01 06:43

I understand services and such are being clamped down on, so my receiver has stopped working in Android Oreo.

I have this code starting the service -



        
相关标签:
2条回答
  • 2021-01-01 07:01

    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

    0 讨论(0)
  • 2021-01-01 07:03

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题