|
8 | 8 | import android.content.Intent;
|
9 | 9 | import android.content.IntentFilter;
|
10 | 10 | import android.os.Bundle;
|
| 11 | + |
| 12 | +import androidx.annotation.NonNull; |
11 | 13 | import androidx.core.app.NotificationManagerCompat;
|
12 | 14 |
|
13 | 15 | import com.dieam.reactnativepushnotification.helpers.ApplicationBadgeHelper;
|
|
28 | 30 |
|
29 | 31 | import android.util.Log;
|
30 | 32 |
|
| 33 | +import com.google.android.gms.tasks.OnCompleteListener; |
| 34 | +import com.google.android.gms.tasks.Task; |
| 35 | +import com.google.firebase.iid.FirebaseInstanceId; |
| 36 | +import com.google.firebase.iid.InstanceIdResult; |
31 | 37 | import com.google.firebase.messaging.FirebaseMessaging;
|
32 | 38 |
|
33 | 39 | public class RNPushNotification extends ReactContextBaseJavaModule implements ActivityEventListener {
|
@@ -84,15 +90,24 @@ public void onNewIntent(Intent intent) {
|
84 | 90 |
|
85 | 91 | private void registerNotificationsRegistration() {
|
86 | 92 | IntentFilter intentFilter = new IntentFilter(getReactApplicationContext().getPackageName() + ".RNPushNotificationRegisteredToken");
|
| 93 | + final RNPushNotificationJsDelivery fMjsDelivery = mJsDelivery; |
87 | 94 |
|
88 | 95 | getReactApplicationContext().registerReceiver(new BroadcastReceiver() {
|
89 | 96 | @Override
|
90 | 97 | public void onReceive(Context context, Intent intent) {
|
91 |
| - String token = intent.getStringExtra("token"); |
92 |
| - WritableMap params = Arguments.createMap(); |
93 |
| - params.putString("deviceToken", token); |
94 |
| - |
95 |
| - mJsDelivery.sendEvent("remoteNotificationsRegistered", params); |
| 98 | + FirebaseInstanceId.getInstance().getInstanceId() |
| 99 | + .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { |
| 100 | + @Override |
| 101 | + public void onComplete(@NonNull Task<InstanceIdResult> task) { |
| 102 | + if (!task.isSuccessful()) { |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + WritableMap params = Arguments.createMap(); |
| 107 | + params.putString("deviceToken", task.getResult().getToken()); |
| 108 | + fMjsDelivery.sendEvent("remoteNotificationsRegistered", params); |
| 109 | + } |
| 110 | + }); |
96 | 111 | }
|
97 | 112 | }, intentFilter);
|
98 | 113 | }
|
|
0 commit comments