I'm working on a project that need to be updated, but I don't have very clear what I need to change. I have the idea that the best option is to migrate to FCM but my boss disagree with me.
My source code of the receiver:
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(), GcmNotificationHandlerIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
I'm getting the next error on Android 8 (sdk > 26).
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.mediobanapp.pushMessages.gcm.GcmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.medioban cmp=com.medioban/com.mediobanapp.pushMessages.gcm.GcmNotificationHandlerIntentService (has extras) }: app is in background uid UidRecord{c6926af u0a161 RCVR idle procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3682)
at android.app.ActivityThread.-wrap18(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1969)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7390)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.medioban cmp=com.medioban/com.mediobanapp.pushMessages.gcm.GcmNotificationHandlerIntentService (has extras) }: app is in background uid UidRecord{c6926af u0a161 RCVR idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1701)
at android.app.ContextImpl.startService(ContextImpl.java:1657)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:91)
at com.mediobanapp.pushMessages.gcm.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:14)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3672)
at android.app.ActivityThread.-wrap18(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1969)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7390)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)