Firebase on Android - I want to disable firebase notifications on Android client

前端 未结 5 1814
忘掉有多难
忘掉有多难 2020-12-16 13:38

I\'m using Firebase console to send notifications to users. However I want to let users disable notifications. How can I disable them?

I am able to handle (and stop)

5条回答
  •  我在风中等你
    2020-12-16 14:20

    I couldn't comment yet, but racs' comment helped me a lot.

    Actually, Firebase docs recommend to use data push instead of notifications if you want to have complete control over how it is handled: firebase.google.com/docs/cloud-messaging/… - quote: "Use notifications when you want FCM to handle displaying a notification on your client app's behalf. Use data messages when you want your app to handle the display or process the messages on your Android client app..."

    So basically, I changed the body for the push notification request from:

    {
       "data": {
           "type" : "mytype"
        },
        "notification": {
            "title": "My Title",
            "body": "My Notification Message"
        },
        "to": "/topics/all"
    }
    

    To:

    {
       "data": {
           "type" : "mytype",
           "title": "My Title",
           "body": "My Notification Message"
        },
        "to": "/topics/all"
    }
    

    Now my app calls onMessageReceived() everytime even in background, and I just changed the methods to use the obtained notification title and message in the push data.

提交回复
热议问题