Служба сообщений Firebase не получена, когда приложение закрыто - PullRequest
0 голосов
/ 01 октября 2019

Firebase Messaging Service Не получено, пока приложение закрыто в фоновом режиме. Похоже, что сообщение отправляется, когда я отправляю сообщение

{
    "multicast_id": 5871474003172698383,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1569854682800517%358f5cee358f5cee"
        }
    ]
}

Однако уведомление не будет получено до тех пор, пока приложение не будет открыто.

и пока экран телефона выключен, изображение не загружается

        .setStyle(new NotificationCompat.BigPictureStyle()
                .bigPicture(image)
                .bigLargeIcon(null))

что мне не хватает?

post Json

{
    "to": "fai1***************V0h6PuF5UA",
    "collapse_key": "type_a",
    "notification": {
        "body": "Body 5",
        "title": "Title"
    },
    "data": {
        "image": false,
        "image_url": "https://res.cloudinary.com/yhackup/image/upload/v1569505733/indirim_copy.png",
        "intent_url": "http://polisoft.com.tr/Blog/musteri-destek-ve-egitim-personeli-alinacaktir"
    }
}

Manifest Tag

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

MyFirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";

    @Override
    public void onSendError(@NonNull String s, @NonNull Exception e) {
        Log.e("onMessageReceived",s);
        super.onSendError(s, e);
    }

    // [START receive_message]
    @SuppressLint("WrongThread")
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.e("onMessageReceived","Mesaj Geldi.");
        if (remoteMessage.getNotification() != null) {
            if (remoteMessage.getData().size() > 0) {
                JSONObject jsonObject = new JSONObject(remoteMessage.getData());
                boolean isImage = jsonObject.optBoolean("image", false);
                if (isImage) {
                    new sendImageNotification().execute(
                            remoteMessage.getNotification().getTitle(),
                            remoteMessage.getNotification().getBody(),
                            jsonObject.optString("image_url"),
                            jsonObject.optString("intent_url"));
                } else {
                    sendNotification(
                            remoteMessage.getNotification().getTitle(),
                            remoteMessage.getNotification().getBody());
                }
            }
        }
    }
    // [END receive_message]


    // [START on_new_token]

    @Override
    public void onNewToken(String token) {
        Log.d(TAG, "Refreshed token: " + token);
        sendRegistrationToServer(token);
    }
    // [END on_new_token]


    private void sendRegistrationToServer(String token) {
        Context context = this;
         Tools.SendFirebaseInstanceId(token, context);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...