How to send GCM device token to IBM Bluemix - android

I am getting device token from GCM. But in IBM Bluemix Cordova documentation,they are never sending Device Token.
Then how will the device will be registered in Bluemix for individual push notification.
Link to Cordova Blemix Doc - DOCUMENTATION

When you register the device with the Bluemix Push service, the success message returned will contain the Device ID.
var success = function(message) { console.log("Success: " + message); };
var failure = function(message) { console.log("Error: " + message); };
MFPPush.registerDevice({}, success, failure);
Is that what you mean by Device Token?
Update
The GCM service provides the Device token which the SDK validates and updates with the Bluemix Push service.
You can find more details and an extensive timeline outlining the process # https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push
Scroll down to "Push Notification SDK flows for hybrid Android Apps"

Related

Device-Device communication in react native app based on firebase

I have just started learning react-native and thinking of integrating firebase to it. Now consider my question scenario:
There are two users A & Bwho have the react app running in their device( none of them are admin). Now I have studied that when we connect our react native app to firebase, every instance of the app running on a device gets a unique token and that token is stored in firebase itself.
Now suppose user A wants to send a " notification or message" to user B. Now see the below code I saw on firebase official website:
// This registration token comes from the client FCM SDKs.
var registrationToken = 'YOUR_REGISTRATION_TOKEN';
var message = {
data: {
score: '850',
time: '2:45'
},
token: registrationToken
};
// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
This method seems quite straightforward, but is there really any method using which user A can know the unique token of user B like this:
const token= firebase.getToken('B');
And then use this token in the above code to send notification to user B. Is it poosible to do it using firebase?
Thank You.
The code you found uses the Firebase Admin SDK to send messages. This SDK grants its users full administrative access to the Firebase project, so can only be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. It cannot be used in the app you send to your users.
You will need a trusted environment to send the messages to the users. For more on this, see:
The Firebase documentation on FCM architecture, which has this handy diagram
How to send one to one message using Firebase Messaging
How to send Device to device notification by using FCM without using XMPP or any other script.?

Implementing Ti.goosh push notification module in Titanium for Firebase support

I have implemented Ti.goosh module in my app for sending push notification from Firebase. I followed this git document and created a new project in Google Developer Console API. I got a Project Number from there and used it as "GCM sender ID" in tiapp.xml. Then I added following code in my index.js controller.
var TiGoosh = require('ti.goosh');
TiGoosh.registerForPushNotifications({
// The callback to invoke when a notification arrives.
callback: function(e) {
var data = JSON.parse(e.data || '');
},
// The callback invoked when you have the device token.
success: function(e) {
// Send the e.deviceToken variable to your PUSH server
Ti.API.log('Notifications: device token is ' + e.deviceToken);
},
// The callback invoked on some errors.
error: function(err) {
Ti.API.error('Notifications: Retrieve device token failed', err);
}
});
When I run app, success block execute and i got the device token. But I didn't get the message from firebase. I also couldn't understand where the server key and API key from firebase should be included in this module to link with my app.
How can I understand the whole thing? It seems that push notification in Titanium is very complex with very poor documentation.
Use this php script to send notification and confirme you receive the data with ti.goosh
you need to include your api key and device token (registration_ids) in the script

Unable to configure push notification for android in Titanium

To implement push notification service in my titanium app for android, I was going through this development document. At first, I configured push services for android device by creating a "Client ID". I saved the "Client ID" for further use, but i do not understand where this "Client ID" would be need as there is no information for this in the doc. Then I followed this doc to subscribe push notification and added "ti.cloudpush" module to the tiapp.xml. But unfortunately, I'm getting error while calling retrieveDeviceToken() method. Here is my code snippet -
// Require the module
var CloudPush = require('ti.cloudpush');
var deviceToken = null;
// Initialize the module
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: deviceTokenError
});
// Enable push notifications for this device
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
// Process incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
alert("Notification received: " + evt.payload);
});
And here is the error I'm getting in the console -
Failed receiving GCM SenderId. Getting GCM SenderId failed. Max retry time reaches.
Note - I didn't add anything for android manifest in tiapp.xml
When you're using Cloudpush module you will also need to configure the backend with settings. You can find how to do that in the documentation: https://docs.appcelerator.com/platform/latest/#!/guide/Configuring_push_services-section-src-37551713_Configuringpushservices-ConfiguringpushservicesforAndroiddevices
If you want to use your own backend you will need to use a different module for sending push notifications on Android. For example ti.goosh or onesignal
The documentation of both modules will tell you how to configure the senderID.

Sending targeted push notification to Android app, which is based on Azure

I have Android app, which is working with Azure IoT hub.
There are several tables on Azure, one of which stores credentials of registered users of my app. This table has one column called "userId" and records are unique here.
I also have node.js script which will be processing data in one of the tables and sending push notifications based on that data via GCM.
function sendPush(userId, pushText)
{
var payload = pushText;
push.gcm.send(null, payload, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse, payload);
request.respond();
},
error: function (pushResponse) {
console.log("Error Sending push:", pushResponse);
}
});
}
I know that to make targeted push notification with Google Cloud Messaging, you have to get token with InstanceID class.
But can I somehow use "userId" column record to become that token to make my push notification targeted?
Generally speaking, you can leverage Tags param as tag identifier to push notifications to specified device. Refer to Sending push notifications with Azure Notification Hubs and Node.js for more.
And you can register with tags from your backend application, if your requirements are in the proper scenarios listed at https://msdn.microsoft.com/en-us/library/azure/dn743807.aspx
In backend nodejs application, you can try to use following code to register with tags:
var notificationHubService = azure.createNotificationHubService('<nb-name>', '<nb-keys>');
notificationHubService.createRegistrationId(function(err,registerId){
notificationHubService.gcm.createNativeRegistration(registerId,"identifier-tags",function(err,response){
console.log(response)
})
})
Then you can try to use the tags in send function.
Any further concern, please feel free to let me know.

Sending push to Android using SNS

I'm really puzzled about to get the whole chain of sending a push from my .NET backend to my android app using Amazon SNS.
I'm using JustSaying on my backend to send my messages to SNS which is working when I tested it with a email subscriper. This is the code I'm using to send the push:
var publisher = CreateMeABus.InRegion(RegionEndpoint.EUCentral1.SystemName)
.WithSnsMessagePublisher<Push>();
publisher.Publish(new Push("Hello"));
And push class looks like this:
public class Push : Message
{
public Push(string body)
{
Body = body;
}
public string Body { get; set; }
}
Now my problem is, how to I send this push to my specific device?
I created an app on https://developers.google.com for google cloud messaging and have a applicationkey and senderid.
I also set up an API project/app on http://console.developers.google.com and enabled the API for cloud messaging.
In AWS SNS console I also created an application and supplied the above mentioned applikationkey which generated a ARN for the Google Android Platform.
In my android app I'm running this code:
try{
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this.getApplicationContext());
String regId = gcm.register("my-sender-id ");
} catch(IOException e){
}
I'm fumbling in the dark here and can't find any good turtorial on how to set this up. AWS documentation seems to cover only small parts and seems to be outdated.
Any help on pointing me in the right direction is greatly appreciated.
Thanks!
See the developer guide of SNS http://docs.aws.amazon.com/sns/latest/dg/mobile-push-gcm.html. In short:
Get GCM device token (or regId) as in your code
Register your device to SNS by calling CreatePlatformEndpointRequest with your device token. You will get a platform endpoint ARN which is the identifier of this device in SNS.
Send notification to the device. Use Publish to publish notification to the platform endpoint ARN
Alternatively, you can subscribe your device to a particular SNS topic. Then you will be able to publish a notification to the topic, and SNS will broadcast it to all subscribers.

Categories

Resources