I have implemented Firebase cloud messaging in my app for push notifications. Everything working fine. But notifications are getting even user logged out from app. If user uninstalled the app directly then how can i unsubscribe the topic notification. if i have subscribe the a topic and now i unsubscribe the topic and subscribe the new topic then i also receiving notification for old subscribe topic also.
When you uninstall the app, the service handling the FCM messages and notifications will also be removed from the device. So you won't be receiving any push notifications once you uninstall.
if your are subscribing to fcm topic then there is way to unsubscribe from that topic to not recieve any notifications for that topic.
below is the method you need :
unsubscribeFromTopic (String topic)
check google firebase docs here :
https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessaging
Related
In Firebase cloud function can send push notification to any user if the user device token is stored in Firebase database. Again if the user subscribes to a topic then also another user can send a notification to the user. Now the question is that in what situation we should use topic messaging and in what situation we should use cloud function to send the notification. If any user subscribes to his unique ID (as provided by Firebase) then anyone can send topic messaging to him by publishing topic messaging to that unique ID. Is it a good approach or we should use cloud function to send push notification to that user using the device token. Is it a good idea to subscribe to his own unique ID to get a notification. Please help me to resolve my issue. Is topic messaging is free to use?
Firebase Cloud Messaging is completely free to use, including the use of topics.
When you use topics, you separate the sending of messages about a topic, from the fact that an install of your app subscribes to that topic. This means you can add subscribers to the topic later, without having to write additional code or even data (as the list of tokens that are subscribed to a topic is handled by FCM itself).
On the other hand: topics are public. Once somebody knows the topic ID, they can subscribe to that topic, and receive any messages you send to that topic.
The alternative to using topics is sending messages directly to FCM Instance ID tokens. In that case you'll keep a list of tokens somewhere yourself, and determine what token(s) to deliver the message to. In this case, you fully control who receives the message, but will have to maintain your own list of tokens, and the mapping of what token receives what message(s).
Note that sending messages (no matter whether to topics or to tokens) can be done from any trusted environment, like your development machine, a server you control, or Cloud Functions. And sending messages (no matter whether to topics or to tokens) can't be (securely) done from the client-side code.
I am trying to send a push notification when user is going to uninstall my Android app. My idea is to use Firebase Cloud Messaging and Google Analytics for Firebase Triggers. In order to be able to use triggers I have been marked "app_remove" event as conversion in Firebase Console of my app. It is possible send notifications using Firebase Cloud Messaging triggered by a Firebase function as described in this question, but when my app is uninstalled It will not be able to show incoming message from FCM as a push notification. It is possible to setup the incoming message to be displayed as push notification even my app is uninstalled?
It is possible to setup the incoming message to be displayed as push notification even my app is uninstalled?
Not possible.
When your app is uninstalled, the corresponding registration token tied to that specific app instance is also invalidated.
The registration token is what FCM uses to send messages to the corresponding device, if invalidated, FCM will no longer have any way to send messages to that device.
I use Firebase Cloud Messaging to send notifications to the users using my app.
But the notifications only arrive after the user opened the app the first time.
Can somebody help me?
Thanks
Florian
Have you followed the Firebase FCM properly? The FCM token is triggered when FCM token is not created yet in users phone. If existed, the push notification will not be a problem if the app is not open. You can called onTokenRefresh() to init the FCM token.
Is possible to send push notifications with firebase without using the console,I mean can I send a push notifications when some user makes some action in the app?
Is possible to send push notifications with firebase without using the
console
Yes you can use Firebase API
I mean can I send a push notifications when some user makes some
action in the app?
You can subscribe to a topic when user makes some action in the app
FirebaseMessaging.getInstance().subscribeToTopic("news");
and send a notification from Firebase web console or use Firebase API to all topic subscribers.
You can send a message to a topic from the Firebase Cloud Messaging API.
But this requires the use of your FCM server key, which means it should only be done from an app server. You should never embed your server key in the client-side app. This means that direct device-to-device notifications are not possible at the moment, you will always need an app server for that.
For a tutorial explaining one possible scenario, see: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
I've implemented Firebase Cloud Messaging in my android app.
Is it possible to turn notifications off from my application settings screen?
It was possible with old GCM as we have broadcast GcmReceiver and we could handle it ourselves.
Now we have only FirebaseInstanceIdService and could handle it only when app is in foreground.
How we can handle it when app is in background?
Is it possible only to disable Firebase Cloud Messaging only for some category of notification inside app or this should be done on the server side?
You can manage whether or not notifications are displayed by always sending data messages from your app server. The Firebase console always sends notification messages, which are the types of messages that generate notifications automatically when your app is in the background. So if you want full control of when notifications are displayed use data messages which are only available from your app server, not yet from the Firebase console. See more on message types here.
I came with the solution to send request to the server if I need to switch on/off some type of notifications. And if send request to switch off some notification server will no longer trigger FCM server to send notification to the device