Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix][Android] Use JobServiceIntent to fetch the FCM token in the background #678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

<service
android:name=".fcm.FcmInstanceIdRefreshHandlerService"
android:exported="false" />
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down