Уведомление FCM не получено, является ли приложение фоновым или передним - PullRequest
0 голосов
/ 10 июля 2019

Я не получаю уведомления после отправки с помощью компонента уведомлений firebase или почтальона, хотя я получаю успешные отзывы от обоих

  • Я ознакомился с документами Firebase о том, как это реализовать.

  • Я также пробовал ответы на подобные вопросы, но до сих пор нет получение уведомления

  • Тем не менее, когда я использовал почтальон, я получил успешный ответ, но Появляется уведомление

AndroiManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fcmpushnotification">
    <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">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".helper.MyFirebaseMessageService"
            android:exported="false"
            >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

    </application>

</manifest>

FCM SERVICE CLASS

public class MyFirebaseMessageService extends FirebaseMessagingService {

      @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        Log.d("FIREBASETOKEN", "testing if method is called ");

        //checking if , there is any notification
        if (remoteMessage.getNotification()!=null) {
            String title = remoteMessage.getNotification().getTitle();
            String message = remoteMessage.getNotification().getBody();
            NotificationHelper helper = new NotificationHelper();
            helper.setBody(message); helper.setTitle(title);
            NotificationHelper.displayNotification(getApplicationContext(), helper);
            Log.d("FIREBASETOKEN", "notification is not empty");

        }else {
         //Toast.makeText( , "notification is empty" , Toast.LENGTH_LONG).show();
            Log.d("FIREBASETOKEN", "notification is empty");
        }


    }
}

Использование почтальона корпус {

 "to" : "cI1AZOAfrv8:APA91bFQUcKD6gGIfCHplDXCMCFvgk9K2b-jwsN2g_3omDMM0_y_twT0SpqWYzoBWhzWYhcsedbNZCfsygBqDVT5nECOL9sBM7mKFn_4oxry7H8P_rxVvvPRCTXWitxw4V2xd2Gkbmtb",
 "collapse_key" : "type_a",
 "notification" : {
     "body" : "Body of Your Notification",
     "title": "Title of Your Notification"
 }
}

ответ

{
    "multicast_id": 6756762729932992317,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1562751631028566%77e482e477e482e4"
        }
    ]
}

Я ожидал получить уведомление, и журналы в onMessageReceived() должны быть зарегистрированы, но ничего не получается

1 Ответ

0 голосов
/ 10 июля 2019

похоже, что вы пропали без разрешения интернет. добавить следующее разрешение в манифест

<uses-permission android:name="android.permission.INTERNET" />

и интернет должен быть включен на вашем устройстве.

...