public class RegisterIntentService extends JobIntentService {
static void enqueueWork(Context context, Intent work) {
enqueueWork(context, RegisterIntentService.class, JOB_ID, work);
}
@Override
protected void onHandleWork(@NonNull Intent intent) {
Timber.d("onHandleIntent");
String token = null;
InstanceID id = InstanceID.getInstance(this);
Registrar registrar = RegistrarFactory.create();
try {
token = id.getToken(registrar.getSenderId(), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Timber.d("received token");
} catch (Exception e) {
Timber.e(e, "unable to handle intent");
}
Intent registrationComplete = new Intent(Preferences.REGISTRATION_COMPLETE);
if (token != null) registrationComplete.putExtra(Preferences.REGISTRATION_ID, token);
this.sendBroadcast(registrationComplete);
}
}
in Manifest file :
<service
android:name="com.tesco.pushnotification.RegisterIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false" />
below exception is getting when I send the push notification when APP is in Background.
> Process: com.tesco.clubcardmobile, PID: 8326
> 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.tesco.clubcardmobile
> cmp=com.tesco.clubcardmobile/com.tesco.pushnotification.GCMListener_Service
> (has extras) }: app is in background uid UidRecord{f0a6ce6 u0a2340
> RCVR idle procs:1 seq(0,0,0)}
using given code i am able to get Push Notification when APP is in Foreground but not in Notification manager. i have changed my code for Android Oreo before Android Oreo i was able to get Notification in background but I don't know why i am not getting When app is in Background after changed API 26 Migration I have changed IntentService to JOBIntentservice please suggest me what i am doing wrong suggest me in given Error what wrong i am doing .