【发布时间】:2018-12-23 12:13:42
【问题描述】:
我目前正在使用在 Oreo 中崩溃的 startWakefulService 函数。我意识到我要么必须切换到 startForegroundService() 并使用前台服务,要么切换到 JobIntentService 但根据我下面的代码,我不确定该怎么做。 (对不起,我是一个安卓新手)。任何正确方向的观点将不胜感激。
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 (has extras) }: 应用在后台 uid UidRecord{f602fba u0a114 RCVR idle procs:1 seq(0,0,0)}
【问题讨论】:
标签: java android android-8.0-oreo