Android Parse SDK not picking up deviceToken - android

I have a self hosted parse-server, when i create a new android user the device token in the database doesn't get set. as a note i am using fcm for push
has anyone got FCM to work with parse server?

I dont think this is possible. Reading from the Pushwoosh website who replaced Parse (since Parse was acquired by Facebook):
GCM Android Push notifications, which are being replaced by FCM now,
require you to create a Project in Google Developer Console and use
your own Sender ID and Server Key. In order to simplify the
configuration process, Parse offered to use their internal Sender ID
and Server Key to send push notifications. If you used the default
Parse Android push configuration settings and didn’t register your own
GCM sender ID and GCM Server key, all your GCM tokens belong to Parse.
This is what we never did at Pushwoosh and we always asked our users
to register their own GCM Sender ID and GCM Server Key. What is
important to understand is that Parse will never share his Private
Server Key as it would compromise all Android push tokens from any
Parse-based project.
What Does It Mean?
It means that you can use the default Sender ID and API key registered
in Parse only to send push notifications via Parse. You can’t migrate
these device tokens to another push service since you don’t have
Parse’s Server Key. In that way these tokens can be considered gone.
The only solution – you should start collecting new push tokens as
soon as you can.
In short you have to use only one.

i actually found a solution.
via https://firebase.google.com/support/guides/parse-android#firebase-notifications
so effectively there is a fix, parse uses the old way of collecting the token via gcm request token method, fcm now auto calls for a token at the time the application first installs. this creates a mismatch hence parse doesn't actually work well with fcm sdk.
but you can actually use them together and although both gcm and fcm get different tokens both these tokens actually point to the same device. i have tested this and it does work well using both tokens from a private parse server.
you must ensure you are using the "ParsePushBroadcastReceiver" or either you use a custom class as the link says. thing is you "FirebaseMessagingService" class and you custom gcm receiver class will both fire when a message comes in. so what i did was receive messages with the FirebaseMessagingService class and filter as required.

Related

On Android, can my app's FCM secrets be used to impersonate my app?

I have an Android app set up to receive FCM push notifications. The app registers with my server with the FCM token. My idea is to prove that the token comes from my app by sending a push notification to the token. It will only arrive at my app, right?
I am wondering if a bad actor could extract the FCM secrets (configured with google-services.json) from my app, make an app with my package name, and trick people into installing it on their device. When the malicious app registers to my server, I suspect that I can't tell if it's coming from the right app. I also suspect the if I send a push notification to the token, it will be sent without errors. Am I correct?
Any help here is much appreciated.
There are no secrets from google-services.json that get embedded in your app. See my answer here: Is it safe to expose Firebase apiKey to the public?
With the information in google-services.json all you can do is receive messages, you won't be able to send them with just that information.
To send messages to a user you also need to specify the FCM server key when calling the API (or provide credentials otherwise that prove you're an authorized collaborator on the project). This information is not available in the google-services.json and should never be used in the client-facing application code.

Can Cordova's device.uuid value be used to send Firebase push notification?

I am trying to build a wrapper app with cordova and using PHP as server backend.
I am using cordova-plugin-fcm to handle push notification.
Correct me if I am wrong, each device (android and ios) has own id which is used to send notification.
How can I get that id and send it to PHP route so that I can bind it with the logged in user and send notification?
//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
In above example token is the id to be send to PHP to send notification?
Can the device.uuid used for sending notification?
I have already setup my Firebase configuration and the project has google-services.json and GoogleService-Info.plist in place.
Thank you
Firebase Cloud Messaging targets its messages at a specific app on a specific device. Each specific app install is identified by Firebase's Instance ID, also referred to as a device registration token, or an FCM token.
The Firebase documentation on accessing the registration token says this about it:
On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseMessagingService and overriding onNewToken.
From a quick read through the Cordova documentation on device.uuid, this seems to merely identify the device, and not the app on the device. Since FCM messages are delivered to a specific app on each device, it seems unlikely you can use the UUID of the device as a replacement.
Even if the UUID is unique for each app on each device, it won't be a drop-in replacement, as FCM only works with its own registration tokens. At the very least you'll need to keep a mapping of the device.uuid values to their corresponding FCM token.

How to verify GCM sender ID of deviceToken in Parse.com

We are using Parse.com to send push notifications. With the announced shutdown, we're now looking into how to migrate to another service. On Android, we haven't configured any GCM sender ID so we have been implicitly using Parse.com's sender ID. That's a problem for the migration (see Urgent note for Parse Android Push users and Migrating an Existing Parse App (section Exporting GCM Registration IDs)).
Therefore, we are now preparing a new version of our Android app with our own GCM sender ID. Is there any way in Parse.com to verify which devices (installation) are associated with our sender ID? How can we check if our update was successful? Does Google provide any API for directly or indirectly checking if a sender ID works with our Google project?
Any tool or any approach that involves writing some code is ok.
Thanks for posting this question. I help work on OneSignal and I've updated the mentioned blog post based on the feedback.
The blog post now instructs users to also update their ParseInstallation to set their GCMSenderId, as follows:
final ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
parseInstallation.put("GCMSenderId",YOUR_NEW_SENDER_ID);
parseInstallation.saveInBackground();`
This will allow you to track which users are now subscribed with the new GCM Sender ID. It will also tell our Parse importing tools like ours that these subscribed devices can be imported and used.
The open source Parse Server project does not currently support push notifications, but it is in the roadmap and should be available shortly.
If you wish to migrate your Parse Push app to another GCM provider, you will want to update your Android Manifest file with your own GCM Sender Id. Once the app has been deployed to the Google Play store, clients that update to the latest version of your app will register using your GCM Sender Id as well.
You will want to track how many of your active users have updated to the new version of the app to get a better idea of how well your migration is progressing.
The Parse Installation object automatically tracks the client-side app version number. A quick and easy way of determining how many clients have updated your app to the new version of your app is to filter for Installation objects running the new appVersion or newer.
You should, of course, make sure the updated version of your app has registered with GCM using your new Sender Id properly before you release the new version on the Google Play store. The Android Documentation on Cloud Messaging covers best practices for this. If your app has been configured correctly, you should be able to deliver push notifications to the updated clients using your new push notifications provider.
You can find information regarding sending and receiving push notifications from our guide: https://parse.com/docs/android/guide#push-notifications
In particular
...an advanced feature for developers that want to send pushes from multiple push providers, Parse allows you to optionally register your app for pushes with additional GCM sender IDs. To do this, specify the additional GCM sender ID with the following <meta-data> tag as a child of the <application> element in your app's AndroidManifest.xml...
and
GCMSenderId: This field only has meaning for Android ParseInstallations that use the GCM push type. It is reserved for directing Parse to send pushes to this installation with an alternate GCM sender ID. This field should generally not be set unless you are uploading installation data from another push provider. If you set this field, then you must set the GCM API key corresponding to this GCM sender ID in your Parse application's push settings.

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 Cloud Messaging send notification to all devices

I'm new in GCM. I would like to send an message to all devices that have the app installed. I read about registration_id: after the first connection to GCM, google send this unique string to device. I'm a beginner in server world but if I'm not mistaken, in server side, for sending a notification to devices I have to send array of registration_id and the message to google.
Google knows how has the registration id?
Is there a way to send messages to all devices without pass the registrarions id?
Thank you.
With GCM 3.0 it's now possible to send a notification to all devices thanks to topics support. The app must suscribe to one or more topics and the server can send notifications to that topic without specifying individual devices.
https://developers.google.com/cloud-messaging/topic-messaging
You can suscribe all devices to a topic called "global" and then send the message to "/topics/global" instead of sending them to all the registration_ids.
Is there a way to send messages to all devices without pass the registrarions id?
No way.
After successfully registering on GCM, you (the Android application) should send the registration id to your application server and store them somewhere, in a database for example. This registration id will be used to send a notification to a particular device.
To send a notification to all devices, would mean then to select all the registration ids from that database, and as you said, put them in an array and pass them further to GCM.
Update: With Firebase Cloud Messaging, it is now possible to use https://firebase.google.com/docs/cloud-messaging/android/topic-messaging to send notifications without explicitly specifying registration IDs.
You need to send the list of reg id of devices and also this list should not exceed 1000 this is a limitation of GCM if you want to send message to more than 1000 devices then you need to break the list in chunks of 1000.
YES, there is a way to send a message to all!
Just send in the 'to' field the '/topics/global' value, rather then in the 'registration_ids' field the ids.
For example in php:
'to' => "/topics/global",
and not this:
'registration_ids' => $this->devices
Create the notification_key, which identifies the device group by mapping a particular group to all of the group’s associated registration tokens(You can create notification keys on the app server).
With a notification_key , instead of sending one message to one registration token at a time, the app server can send one message to thenotification_key , and GCM then sends the message to all of the group’s registration tokens.
Also note that maximum number of members allowed for a notification_key is 20.
Google Dev site has added a new guide for this topic in particular.
https://developers.google.com/cloud-messaging/notifications#sending_downstream_messages_to_device_group
I think there is a confusion here. I had used the github sample code (app server in Java deployed to Tomcat for example) and Android app. There, I didn't "pass" or "send" any registration Id to the app server. It called the relevant APIs to retrieve the registration IDs and use them to send notifications. Why is every thread about GCM registration ID saying that one needs to pass registration IDs to 3rd party app server? I am afraid I don't agree. I think 3rd Party app server can query GCM server itself to find out which devices have registered to receive notification from a particular sender (sender id). Having to manually pass the registration IDs to 3rd party app server defeats the whole purpose of automating the process. Maybe I am missing something here or I am using the deprecated content. Anyway, how can an automated process involve manual intervention once it starts?

Categories

Resources