为什么App无法在Android O中接收GCM通知?

时间:2019-06-05 12:23:42

标签: android service google-cloud-messaging intentservice

我正在我的应用程序内部使用GCM。但是在Android O App中,如果进入后台,它将停止接收通知。我正在针对较低的API 26使用StartService,对于较高的API 26 Android设备使用StartForgroundService。还尝试过JobSchedular和JobIntentService,但App仍然因以下错误而崩溃。

Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.teacout.devzspoon cmp=com.teacout.devzspoon/com.devzspoon.services.MyGcmListenerService (has extras) }: app is in background uid UidRecord{cf40c05 u0a582 RCVR bg:+2m52s193ms idle change:uncached procs:1 proclist:22992, seq(0,0,0)}
                                                                           at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1600)
                                                                           at android.app.ContextImpl.startService(ContextImpl.java:1546)
                                                                           at android.content.ContextWrapper.startService(ContextWrapper.java:669)
                                                                           at android.content.ContextWrapper.startService(ContextWrapper.java:669)
                                                                           at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99)
                                                                           at com.google.android.gms.gcm.GcmReceiver.zzf(Unknown Source:23)
                                                                           at com.google.android.gms.gcm.GcmReceiver.zze(Unknown Source:0)
                                                                           at com.google.android.gms.gcm.GcmReceiver.onReceive(Unknown Source:106)
                                                                           at android.app.ActivityThread.handleReceiver(ActivityThread.java:3406)
                                                                           at android.app.ActivityThread.-wrap18(Unknown Source:0) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                           at android.os.Looper.loop(Looper.java:164) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:7000) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 
06-05 17:30:40.508 22992-22992/com.teacout.devzspoon E/UncaughtException: java.lang.RuntimeException: Unable to start receiver com.google.android.gms.gcm.GcmReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.teacout.devzspoon cmp=com.teacout.devzspoon/com.devzspoon.services.MyGcmListenerService (has extras) }: app is in background uid UidRecord{cf40c05 u0a582 RCVR bg:+2m52s193ms idle change:uncached procs:1 proclist:22992, seq(0,0,0)}
                                                                              at android.app.ActivityThread.handleReceiver(ActivityThread.java:3413)
                                                                              at android.app.ActivityThread.-wrap18(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:7000)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

0 个答案:

没有答案