Я только начал работать с Firebase Cloud Messaging, и я настроил все зависимости, службу Firebase, а также ее теги службы в Manifest.
При отправке сообщения с консоли целевые пользователи обнаруживаются, ноПриложение не получает уведомления.Поэтому я установил точку останова на onMessageReceived ().но он не запустился.
Ниже находится моя служба сообщений Firebase
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMessagingServ";
@Override
public void onMessageReceived( RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String notificationBody = "";
String notificationTitle = "";
String notificationData = "";
try{
notificationData = remoteMessage.getData().toString();
notificationTitle = remoteMessage.getNotification().getTitle();
notificationBody = remoteMessage.getNotification().getBody();
}
catch (NullPointerException e){
Log.e(TAG, "onMessageReceived: NullPointerException: " + e.getMessage() );
}
NotificationHelper.displayNotification(getApplicationContext(), notificationTitle,
notificationBody);
Log.d(TAG, "onMessageReceived: data: " + notificationData);
Log.d(TAG, "onMessageReceived: Notification body : " + notificationBody);
Log.d(TAG, "onMessageReceived: notification title: " + notificationTitle);
}
Манифест Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.sys.systec">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
<service android:name=".utility.MyFirebaseMessagingService"
android:stopWithTask="false"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>