diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3fe7aaddb..62031a373 100755
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -271,13 +271,6 @@
-
-
-
-
-
diff --git a/app/src/main/java/org/linphone/LinphoneManager.java b/app/src/main/java/org/linphone/LinphoneManager.java
index b9ba716a4..bdfd9dbc2 100644
--- a/app/src/main/java/org/linphone/LinphoneManager.java
+++ b/app/src/main/java/org/linphone/LinphoneManager.java
@@ -56,6 +56,11 @@ import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
+import androidx.annotation.NonNull;
+import com.google.android.gms.tasks.OnCompleteListener;
+import com.google.android.gms.tasks.Task;
+import com.google.firebase.iid.FirebaseInstanceId;
+import com.google.firebase.iid.InstanceIdResult;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -750,21 +755,26 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
private void initPushNotificationsService() {
if (getString(R.string.push_type).equals("firebase")) {
try {
- Class> firebaseClass =
- Class.forName("com.google.firebase.iid.FirebaseInstanceId");
- Object firebaseInstance = firebaseClass.getMethod("getInstance").invoke(null);
- final String refreshedToken =
- (String) firebaseClass.getMethod("getToken").invoke(firebaseInstance);
-
- // final String refreshedToken =
- // com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken();
- if (refreshedToken != null) {
- Log.i(
- "[Push Notification] init push notif service token is: "
- + refreshedToken);
- LinphonePreferences.instance()
- .setPushNotificationRegistrationID(refreshedToken);
- }
+ FirebaseInstanceId.getInstance()
+ .getInstanceId()
+ .addOnCompleteListener(
+ new OnCompleteListener() {
+ @Override
+ public void onComplete(@NonNull Task task) {
+ if (!task.isSuccessful()) {
+ Log.w(
+ "[Push Notification] firebase getInstanceId failed: "
+ + task.getException());
+ return;
+ }
+ String token = task.getResult().getToken();
+ Log.i(
+ "[Push Notification] init push notif service token is: "
+ + token);
+ LinphonePreferences.instance()
+ .setPushNotificationRegistrationID(token);
+ }
+ });
} catch (Exception e) {
Log.i("[Push Notification] firebase not available.");
}
diff --git a/app/src/main/java/org/linphone/firebase/FirebaseIdService.java b/app/src/main/java/org/linphone/firebase/FirebaseIdService.java
deleted file mode 100644
index 65c595f62..000000000
--- a/app/src/main/java/org/linphone/firebase/FirebaseIdService.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-FirebaseIdService.java
-Copyright (C) 2017 Belledonne Communications, Grenoble, France
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*/
-
-package org.linphone.firebase;
-
-import com.google.firebase.iid.FirebaseInstanceId;
-import com.google.firebase.iid.FirebaseInstanceIdService;
-import org.linphone.settings.LinphonePreferences;
-import org.linphone.utils.LinphoneUtils;
-
-public class FirebaseIdService extends FirebaseInstanceIdService {
- @Override
- public void onTokenRefresh() {
- // Get updated InstanceID token.
- final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
- android.util.Log.i(
- "FirebaseIdService", "[Push Notification] Refreshed token: " + refreshedToken);
-
- LinphoneUtils.dispatchOnUIThread(
- new Runnable() {
- @Override
- public void run() {
- LinphonePreferences.instance()
- .setPushNotificationRegistrationID(refreshedToken);
- }
- });
- }
-}
diff --git a/app/src/main/java/org/linphone/firebase/FirebaseMessaging.java b/app/src/main/java/org/linphone/firebase/FirebaseMessaging.java
index ebe1d0d18..98a9eb30b 100644
--- a/app/src/main/java/org/linphone/firebase/FirebaseMessaging.java
+++ b/app/src/main/java/org/linphone/firebase/FirebaseMessaging.java
@@ -2,7 +2,7 @@ package org.linphone.firebase;
/*
FirebaseMessaging.java
-Copyright (C) 2017 Belledonne Communications, Grenoble, France
+Copyright (C) 2017-2019 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -27,11 +27,25 @@ import com.google.firebase.messaging.RemoteMessage;
import org.linphone.LinphoneManager;
import org.linphone.LinphoneService;
import org.linphone.mediastream.Log;
+import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.LinphoneUtils;
public class FirebaseMessaging extends FirebaseMessagingService {
public FirebaseMessaging() {}
+ @Override
+ public void onNewToken(final String token) {
+ android.util.Log.i("FirebaseIdService", "[Push Notification] Refreshed token: " + token);
+
+ LinphoneUtils.dispatchOnUIThread(
+ new Runnable() {
+ @Override
+ public void run() {
+ LinphonePreferences.instance().setPushNotificationRegistrationID(token);
+ }
+ });
+ }
+
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
android.util.Log.i("FirebaseMessaging", "[Push Notification] Received");