Android Question Doubts regarding Push notifications in GCM vs FCM

Anser

Well-Known Member
Licensed User
Hi,

I am already using GCM Push Notifications in my app without any issues so far. As FCM is the latest, I need to switch to FCM. Before migrating to the new FCM from GCM, I need to find solutions for the following issues.

Using GCM, I am able to send send push notifications either to a particular device only or to all devices.

In GCM, this is possible because, in GCM, there is a registration process and each device requests for a registration with GCM and once successfully registered, Google provides a unique registration token ID for each device. We then store this GCM Registration ID in our database. Using these GCM registration Token ID's we were able to send Push Notifications to a particular device only OR Push notifications to all devices as per our will. We had proper control over it.​

Now with the new FCM, I don't see a registration process for device and it is only a subscription to some topic. As per Erel's Tutorial regarding FCM in this thread https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/
I don't see a Registration process and getting the Token ID, it is just a subscription to the topic using Public Sub SubscribeToTopics in the Service FirebaseMessaging. There seems to no registration and a way to get the unique registration ID from FCM.

May be all devices can be subscribed to a topic named 'General' or whatever meaningful name. So with this kind of setup in FCM, how is it possible to send a push notification only to a particular device. In real life example, suppose, a push notification to a particular device user ONLY saying that "The product that you ordered has been shipped". How is this requirement taken care in FCM ?

Possibility to send notification to all users, at the same time the possibility to send notification only to a targeted device. If this is to happen, then there should be some unique identification for each device is required. right? and we should store this in our database too.

Can a single device subscribe to more than one topic ?

Any ideas will be appreciated

Thanks & Regards
Anser
 
Last edited:

Anser

Well-Known Member
Licensed User
Googling regarding the topic I found the following java code to get the TokenID/Instance ID while registering for FCM.

https://www.simplifiedcoding.net/firebase-cloud-messaging-tutorial-android/

As per the site the following java code is to be used

Create a class named MyFirebaseInstanceIDService.java and write the following code.

B4X:
package net.simplifiedcoding.firebasecloudmessaging;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
/**
* Created by Belal on 5/27/2016.
*/
//Class extending FirebaseInstanceIdService
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";
    @Override
    public void onTokenRefresh() {
 
        //Getting registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
 
        //Displaying token on logcat
        Log.d(TAG, "Refreshed token: " + refreshedToken);
 
    }
    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
    }
}

From the picture below, it look like the Token ID is received by using the above code

FCM Token ID.png



In the FireBase Message sending console, I could see 3 options while sending a message. The message could be send to:-

1. User Segment
2. Topic
3. Single Device

Another related link regarding this http://www.mzan.com/article/37671380-what-is-fcm-token-in-firebase.shtml


I am not sure whether this is already implemented in B4A's FCM Library, or Is it possible or not. May be I am totally wrong in understanding the FCM concepts.

Request someone to confirm this ie. whether this is possible with the current B4A's implementation of FCM

Regards
Anser
 
Last edited:
Upvote 0

AndOrNot

Well-Known Member
Licensed User
As I understand, registration handle is now hide from Google. A device can be registered to any number of token that you want (sure of this, I tried and it works). So Is more easy to implement vs gcm, because in gcm you need to send a message to a key for each device. Now you can send a message to token and Google automatically will redirect the message. You don't need Id of single device, and you can have more than 1 token
 
Upvote 0
Top