我目前正在使用在奥利奥崩溃的startWakefulService函数.我意识到要么必须切换到startForegroundService()并使用前台服务,要么切换到JobIntentService,但根据我的代码,我不知道该怎么做.(对不起,我是一个Android新手).任何正确方向的点都将非常感激.
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GCMIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(), GCMIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在Android 8.x上运行时遇到的当前错误
致命异常:java.lang.RuntimeException无法启动接收器com.heyjude.heyjudeapp.gcm.GcmBroadcastReceiver:java.lang.IllegalStateException:不允许启动服务Intent {act = com.google.android.c2dm.intent.RECEIVE flg = 0x1000010 pkg = com.app.app cmp = com.app.app/.gcm.GCMIntentService(has extras)}:app在后台uid UidRecord {f602fba u0a114 RCVR idle procs:1 seq(0,0,0)}