Get GCM registration id using HTTP in react native - android

I'm building a React Native app and want to include push notifications for Android. We currently have the infrastructure for GCM push from our last app. However this time I need to use the JS code to pass the registration id to our push servers. The old app was a native Java app and used:
gcm = GoogleCloudMessaging.getInstance(mActivityContext);
regid = getRegistrationId(mActivityContext);
I have the API key and sender Id but I need to get the regid using over HTTP not using the Java library used there. I have found https://android.googleapis.com/gcm/register but I can't find any docs on how to use it.

The implementation for this can be done in 2 ways:
Do a volley implementation in android code and pass the result you get to the Javascript through the JS bridge.U can pass it in a form of promise to the javascript.Please refer to the following link:
http://facebook.github.io/react-native/releases/next/docs/native-modules-android.html
Use fetch api.U can use body and headers in the fetch method.Please refer to the following link:
http://facebook.github.io/react-native/releases/next/docs/network.html#using-other-networking-libraries

Related

Android FCM token without colon (:)

I'm building a VoIP app, and I'd like to use FCM to be notified of incoming calls. The FCM token generated on Android contains a InstanceId prefix, followed by a colon (:). However, due to an implementation detail, I am unable to use string that contains colons. Is there a way to generate a valid token that doesn't contain a colon?
Specifically, I'm using react-native-pjsip, and the library crashes when I pass the token in the contact params, since it contains a colon. It works when I wrap the string in double-quotes (" "), but my SIP provider doesn't support parsing these strings in quotes. So I'm trying to find a way to generate a token that will keep both sides happy, which is one that doesn't contain a colon.
Any help is much appreciated!
There is no API to control what tokens get generated by Firebase Cloud Messaging. So what you'll need to do is encode the token you get into a value that is valid for your infrastructure. For example, you could use a simple URL encoding, which would turn a token a:bc into a%3Abc.

FCM: Invalid registration token. Check the token format

I’m implementing Firebase Cloud Messaging (FCM) and am experiencing a problem that I’m unable to solve. I have implemented FirebaseMessagingService and FirebaseInstanceIdService according to the guide(s). When I go to Firebase Console for my app, and use the Notification function, I can successfully send a message to ALL my app instances (using the package name).
Now, in the code I have fetched the Firebase Instance Id (token) by use of the following code:
String token = FirebaseInstanceId.getInstance().getToken();
SendFirebaseTokenToServer(token);
(note that currently I’m using HTTP protocol, as my server does not yet have a cert). Anyway using the token I get from the call above, I go back to the Firebase Console and try to send a message to one (1) installed instance of my app. I grab the token from our server DB where it is stored as "varchar(max)". When I do that I get the following error message:
Invalid registration token. Check the token format.
I have googled that and found only one hit (having to do with Firebase and iOS):
http://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format
That issue indicates that a cert was required (I think I’m reading it correctly). I’m not sure what I’m doing wrong. I need to get this to work using the Firebase Console first, then my server guy can start on his end knowing that it should work.
Turns out i was programatically encoding all POST or PUT parameters prior to sending to our server. the FCM token had a semicolon in it, which got encoded to a "%3A", seemingly causing the problem.
do NOT encode the FCM token.

get include_player_ids params values for POST request in Postman

I'm working on Remote Notifications in my Ionic App using OneSignal.
I have created an App in OneSignal, configured it for my app and initiated the service as per the Official Docs.
To test this, I am using Postman Chrome Extension. So, after adding the POST Request URL, where can I find the String values for the include_player_ids key.
I have my app still in testing state.
What's the code in typescript to get the value of include_player_ids from our Mobile Device?
Assuming you are using the OneSignal Native Android SDK, you should use the OneSignal idsAvailable method to get the device's OneSignal Player Id and then pass this value to your server.
window.plugins.OneSignal.getIds(function(ids) {
console.log('getIds: ' , ids);
self.deviceToken = ids.pushToken;
self.userId = ids.userId;
console.log(self.userId);
});
That gives u deviceToken and OneSignal User ID, which is referred to as Player ID
I copied the value from the console and used!
Thanks #Saiy2k

How to specify application server URL when setting up GCM in Android?

I can't find this question answered (or addressed) anywhere else, so maybe I am just missing something really obvious, but I have followed these official GCM steps to get GCM added to my Android project and have got stuck.
My first issue is that the documentation states...
...copy the Server API key. Before running the app, you'll need to add this as the value of API_KEY in line 31 of GcmSender.java.
...but what/where is GcmSender.java?
And, my main question, how/where do I specify the URL of my application server in my Android project?
NB - I am using Android Studio. I haven't created my application server yet, but will be doing so with a PHP script that uses HTTP messaging.
The first step is creating 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 a client project; and API server key (created at Credentials), which will be used as API_KEY in a server project.
You can find more at my simple guide at the following questions:
Adding Google Cloud Messagin (GCM) for Android - Registration process
How to implement a GCM Hello World for Android using Android Studio
Hope this helps!
Have just found it.
In the RegistrationIntentService.java file, there is an empty sendRegistrationToServer(String token) method, so the URL of my application server (and the rest) needs to go in there.

Getting Blank messages in my app from AWS SNS.

I want to send push notification to individual using android GCM. have created the app in SNS. I am using aws-sdk v1.4 for Ruby.
When I send through Amazon web interface I receive the messages, but When I publish it through using the code below, I get blank messages. what is the right message format to send?
sns = AWS::SNS::Client.new
endpoint = sns.create_platform_endpoint(platform_application_arn:my_token)
sns.publish(target_arn:endpoint:endpoint_arn, message: "GCM:{data:{message:"GCM:{data:{message:'hello'}")
Please help.
TIA
{"GCM": "{ \"data\": { \"message\": \"hello\" } }"}
Do not call to_json method also set the subject parameter in publish.
The message should be a valid JSON string if you want to publish a message to GCM. You can use to_json to serialize a hash object to JSON. Here is a article about using AWS SDK for Ruby http://blog.tryneighborly.com/amazon-sns-for-apns-on-rails/.
For more information about Amazon SNS:
Send Custom Platform-Specific Payloads in Messages to Mobile Devices
Getting Started with Google Cloud Messaging for Android
Ruby doc for Aws::SNS::Client

Categories

Resources