diff --git a/lib/android/app/src/main/AndroidManifest.xml b/lib/android/app/src/main/AndroidManifest.xml index 5b06abe7e..abd988a58 100644 --- a/lib/android/app/src/main/AndroidManifest.xml +++ b/lib/android/app/src/main/AndroidManifest.xml @@ -20,7 +20,8 @@ + android:exported="false" + android:permission="android.permission.BIND_JOB_SERVICE" /> diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index 5f513d3fa..db9eabaa4 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -144,6 +144,6 @@ protected void startFcmIntentService(String extraFlag) { final Context appContext = getReactApplicationContext().getApplicationContext(); final Intent tokenFetchIntent = new Intent(appContext, FcmInstanceIdRefreshHandlerService.class); tokenFetchIntent.putExtra(extraFlag, true); - appContext.startService(tokenFetchIntent); + FcmInstanceIdRefreshHandlerService.enqueueWork(appContext, tokenFetchIntent); } } diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java index dd2cc9a21..972ac369d 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmInstanceIdRefreshHandlerService.java @@ -1,19 +1,22 @@ package com.wix.reactnativenotifications.fcm; -import android.app.IntentService; +import androidx.annotation.NonNull; +import androidx.core.app.JobIntentService; +import android.content.Context; import android.content.Intent; -public class FcmInstanceIdRefreshHandlerService extends IntentService { +public class FcmInstanceIdRefreshHandlerService extends JobIntentService { public static String EXTRA_IS_APP_INIT = "isAppInit"; public static String EXTRA_MANUAL_REFRESH = "doManualRefresh"; + public static final int JOB_ID = 2400; - public FcmInstanceIdRefreshHandlerService() { - super(FcmInstanceIdRefreshHandlerService.class.getSimpleName()); + public static void enqueueWork(Context context, Intent work) { + enqueueWork(context, FcmInstanceIdRefreshHandlerService.class, JOB_ID, work); } @Override - protected void onHandleIntent(Intent intent) { + protected void onHandleWork(@NonNull Intent intent) { IFcmToken fcmToken = FcmToken.get(this); if (fcmToken == null) { return;