简体   繁体   中英

Android Oreo background limit

I'm using Eclipse's Paho android library. This library internally starts a Service to fetch data. Now when my app is in background and push notification comes, Paho's service works well for pre-oreo devices. But on Oreo device, this work for few minutes duration after app goes to the background state. After this duration, although I'm sending high priority GCM message, service won't starts and gives warning in logcat Background start not allowed . As stated in offical docs, for high priority GCM messages, app becomes whitelisted for few minutes. In this case, it should work for high priority GCM message.

From my understanding app should become whitelisted whenever high priority GCM arrives. Is it correct?

To be ready for Android O:

1) Instead of IntentService; your service needs to extend JobIntentService.

2) Instead of onHandleIntent; you need to use onHandleWork.

3) Instead of startService; you need to use enqueueWork.

Check this out. https://developer.android.com/reference/android/support/v4/app/JobIntentService.html

When dealing with broadcasts, you need to make sure the intent is explicit.

private 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);
    }
}

This was from https://commonsware.com/blog/2017/04/11/android-o-implicit-broadcast-ban.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM