Use GCM / Firebase without clientside SDK - android

Is it possible to use GCM without any GCM related logic on the client side? The idea is that mobile app shouldn't store / renew tokens etc. Mobile app should just initialise session with the middleware backend which will return back the internal device id and that's it (backend server will register device in GCM / APNs).
The goal is to reduce client side logic and simplify integration, so the flow probably should look like: APP <-> BACKEND <-> GCM

I do not think you can, the documentation states "this app must register with GCM and get a unique identifier called a registration token". There is a whole song and dance the client has to do with GCM that a backend isn't allowed to do. Plus, if the GCM server doesn't know which device is which registration id, it wouldn't know what client to send a notification to.
To GCM documentation states only one process of registering a client:
The client app obtains a registration token using the Instance ID API. The call to this API must have the authorized entity set to your app server's sender ID, and the scope set to the appropriate value for GCM (depending on your platform). Refer to the API reference for full detail on this API.
The client app passes the registration token to the app server.
The app server saves the registration token and acknowledges to the client app that the process completed successfully.

Related

Google Cloud Messaging - Does Android client have to send registration token to my application server?

I am new to GCM and not clear about the registration process between client and the app server. Since GCM upstream messaging is available, when client registers with GCM, is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
I saw a push notification diagram somewhere that shows no connection between app server and the client. All the communication can be passed through GCM.
Thanks!
is it possible that GCM can send the registration data to app server, so the android client doesn't have to send the registration token/id to app server like the old day?
if you intend to send messages to individual devices you still have to send the reg id to your server.
if you do not need to have the ability to send to individual devices then you can have the app subscribe to topics and then all your server has to do is send a message to a topic and anyone subscribed to that topic will get the message
The client has to inform the token to the app server somehow.
From the docs:
(...)
2 - The client app passes the registration token to the app server
3 - The app server saves the registration token and acknowledges to the client app that the process completed successfully
If you have seen the registration diagram then you may notice that your app connects with GCM server to obtain a key. So basically your app acquires a token ID. That means your app needs to send this id to your server and not GCM server.
Then you can simply send Push Notification to a Single user, Groups of User, or to an Topic.

Is it possible log in with existing xmpp user using gcm css?

I am developing an android chat application using gcm css. My question is that I have already registered user on my xmpp server and I want to login those user using gcm xmpp. I read the google developer tutorials for cloud messaging https://developers.google.com/cloud-messaging/gcm, but there are not much information as per my requirement.
I have some other query as well:-
1) Is gcm server manage users if manage how it manage? Now, We can send message like push notification on particular registration Id. (Using Downstream), But if user uninstall and install the app again then registration id will be changed. So, In this case how can we manage? Will I need the separate server?
If any one have idea. Please reply.
Thanks in advance...
You should need server in order to handle these things.
You need to call your registration mechanism in service class of android; When you get the registration token from GCM during registration save that token in shared preference and send that GCM token with identity such as mobile number/IMEI/Email ID back to the server.
If next time service restarts or GCM token get changes compare with it in shared preference and send the info to server if it doesn't match. In server you can have rest-api/php/java or any other back end tech which will receive request from mobile if in case registration ID changes.
I have checked below links during development which really helped me could help you in case.
Google Samples of GCM
Chat App with XMPP
Chat App using XMPP Smack api

Steps to receive GCM push notification message from app server

We are developing apps both in IOS and Android. GCM push notification has been enabled for IOS and its working fine now. The package name for both the platforms are going to be the same.
I was given SERVER API KEY and SENDER ID by ios developer to set up gcm for android. While looking for the steps, I came across https://developers.google.com/cloud-messaging/android/client.
I kept to myself that the steps listed in the contents need to be done to set up GCM for android (please correct me if I am wrong).
Get Config file and add it to Android project
Set up Google play services (I added gcm in my project dependency)
Add entries to Manifest file
Check for google play services APK
Obtain registration token.
"An Android application needs to register with GCM connection servers before it can receive messages"
"The client app should store a boolean value indicating whether the registration token has been sent to the server." - My backend team told me I dont need to send them anything I have to just configure gcm in the app and the app will receive messages from backend.
So, My question is Do I need to have RegistrationIntentService and MyInstanceIDListenerService. Also, Do I have to define my InstanceIDListenerService in Manifest?
Our backend uses device id to send push notifications to devices so they dont need registration token to be sent to them as we send device id. So in this case, Should I register my app with GCM using RegistrationIntentService and InstanceIDListenerService? if so, should the app keep the registration token with itself. Is this registration needed?
GCM supports three types of downstream (server-to-client) messaging: send to a specific device (also called "simple" or "targeted"), send to a topic, or send to a device group. Your question says, "our backend uses device id to send push notifications to devices". It is not clear what "device ID" is and which type of messaging you intend to use. Your backend team has told you that you "don't need to send them anything". If that is true, I don't know where they are getting the "device ID".
Each of the three types of messaging provided by GCM require client devices to register with GCM and obtain a registration token. To send a message to a specific device, the registration token is effectively the "device ID". So yes, you need to implement something similar to the RegistrationIntentService and InstanceIDListenerService described in the documentation.
The description in the documentation about needing to send the registration token to the App Server is misleading. That is only required for targeted messaging. The documentation for receiving topic messages states: "Note that, for topic messaging it's not required to send the registration token to your app server; however, if you do send it, your server can verify the validity of the token and get more information about the app that created it."

Google GCM, token vs registration id

I am confused on relationship between registration id and tokens. In the tutorial for GCM from Google, we register for a registration id in the beginning. However, we also get a token. Now, in the diagrams, we send the registration id to the targeted server. However, do we also send the token? I know that the token is derived from the registration id. Is the token used as an authentication mechanism between GCM and the app and the server never knows about the token?
If you are looking for a basic knowledge about Google Cloud Messaging, IMO, you can refer to the following:
Basically, you need to do the steps:
Create a new project at Google Developers Console . At this
step, for simplicity, you just need to take note of 2 values: Project Number, which
will be used as SENDER_ID in the client project; and API server key (created at Credentials), which
will be used as API_KEY in the server project.
Create a new simple Android project for server side (with basic source code as my answer in the following links).
Create a new simple Android project for client side (with basic source code as my answer in the following links, I customized from the original source at Google Cloud Messaging - GitHub).
Run the client app, you will get the registration token (means that your device has successfully registered). Then, paste (hard-code) this token at CLIENT_REGISTRATION_TOKEN variable in server app (or write code to send this token to server app).
You can read more at the following questions, one of them you have read before with one of your previous questions:
How to implement a GCM Hello World for Android using Android Studio
Adding Google Cloud Messagin (GCM) for Android - Registration process
For more information:
Key Concepts from Google Cloud Messaging: Overview
Credentials
Sender ID A unique numerical value created when you configure your API project (given as "Project Number" in the Google Developers Console). The sender ID is used in the registration process to identify an app server that is permitted to send messages to the client app.
API Key An API key saved on the app server that gives the app server authorized access to Google services. In HTTP, the API key is
included in the header of POST requests that send messages. In XMPP,
the API key is used in the SASL PLAIN authentication request as a
password to authenticate the connection. You obtain the API key when
you configure your API project.
Registration Token An ID issued by the GCM connection servers to the client app that allows it to receive messages. Note that
registration tokens must be kept secret.
Hope this helps!
GCM now uses the concept of an InstanceID which represents a single install of an app on a device (Android or iOS). Each InstanceID can issue several tokens. These tokens are used to identify the InstanceID and can expire and be refreshed.
On the client device, you initialize an InstanceID, then with that InstanceID you generate a token (registration token). You send that token to your server, which uses the token to send messages to the InstanceID (installed application). If that token is invalidated for any reason like the application is uninstalled or the token is compromised, a new token should be generated and sent to your server.
I am still successfully registering with registration Id method until 11 May 2016
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.isEmpty()) {
registerInBackground();
}
} else {
Log.i(TAG, "No valid Google Play Services APK found.");
}
APA91bHLUfr71D6K7VTrRH3LGiLFxGNr3qRi3xOB_yNl0fLYsqhlgYXxHzOhQx2WKgqZI3sqxa1ZPORa0-5YBZ1_OFLm9cEg1bTh7wtrpCsHW91MSs2BMIXrHEqyjj2TeoVxnAzA5U8s

Authenticating access to my GCM server

In my android application, I have utilized G+ logins to authenticate the user on the device, and I have implemented a basic GCM server to get a GCM registration ID for that device as well.
Once a device has both authenticated the user and received a GCM registration ID, I'd like it to let my server know that, for example, registration ID XYZ is associated with tim#gmail.com. This part I understand how to do. What I'm not sure of is how I can make sure that it's REALLY tim#gmail.com.
How can I be sure that the email/GCM registration ID pairs coming from devices is authentic?
Google allows you to verify back-end calls from your Android app by utilizing GoogleAuthUtil
to retrieve a string called an “ID Token”. You send the token to your back end and your back end can use it to quickly and cheaply verify which app sent it and who was using the app.
By passing the ID token with your registration ID call to the server, you can verify that the message is authentic and from your Android app.

Categories

Resources