GcmBroadcastReceiver IllegalStateException: Not allowed to start a service intent

I am working on an FCM Push notification in Android, where I get this exception:

GcmBroadcastReceiver IllegalStateException: Not allowed to start a service intent

I searched a lot of questions on this forum, but still have not received help to solve it. My Log and Manifest patch are also given below.

manifest:

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.kolbeh" /> </intent-filter> </receiver> <meta-data android:name="com.parse.push.gcm_sender_id" android:value="id:85490######" /> <service android:name="com.parse.PushService" /> <receiver android:name="dinewhere.fcm.CustomPushReceiver" android:exported="false"> <intent-filter> <action android:name="com.parse.push.intent.RECEIVE" /> <action android:name="com.parse.push.intent.OPEN" /> <action android:name="com.parse.push.intent.DELETE" /> </intent-filter> </receiver> 

Error Log:

 10-16 16:52:19.621 25906-25906/com.kolbeh E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kolbeh, PID: 25906 java.lang.RuntimeException: Unable to start receiver com.parse.GcmBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.kolbeh cmp=com.kolbeh/com.parse.PushService (has extras) }: app is in background uid UidRecord{2ac0a5c u0a888 RCVR idle procs:1 seq(0,0,0)} at android.app.ActivityThread.handleReceiver(ActivityThread.java:3259) at android.app.ActivityThread.-wrap17(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.kolbeh cmp=com.kolbeh/com.parse.PushService (has extras) }: app is in background uid UidRecord{2ac0a5c u0a888 RCVR idle procs:1 seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505) at android.app.ContextImpl.startService(ContextImpl.java:1461) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at android.content.ContextWrapper.startService(ContextWrapper.java:644) at com.parse.ServiceUtils.runIntentInService(ServiceUtils.java:37) at com.parse.ServiceUtils.runWakefulIntentInService(ServiceUtils.java:68) at com.parse.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:21) at android.app.ActivityThread.handleReceiver(ActivityThread.java:3252) at android.app.ActivityThread.-wrap17(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
+5
source share
1 answer

You are running Android 8.0+, with targetSdkVersion from 26+. You cannot reliably call startService() from the background , for example, from the GCM receiver. Instead, you should:

  • Go to startForegroundService() and use the foreground service or

  • Switch to JobIntentService

In your particular case, the code that calls startService() seems to be in Parse. You should see if there is an update for the Parse client that takes into account Android 8.0.

+9
source

Source: https://habr.com/ru/post/1272660/


All Articles