我目前正在使用startWakefulService函数,但在Oreo系统中崩溃了。我认识到我需要切换到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);
}
}
这是在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(有extras)}:应用程序在后台uid UidRecord {f602fba u0a114 RCVR idle procs:1 seq(0,0,0)}。