Push Notification - Mobile to Mobile [duplicate] - android

This question already has answers here:
How to send one to one message using Firebase Messaging
(5 answers)
Closed 3 years ago.
I want to send message from one mobile to another mobile(Push Notification).
Firebase has a push notification service, but it's not directly between mobile to mobile.
It's either mobile to desktop(Upstream), or desktop to mobile(downstream).
Basically the app is supposed to send alert from one mobile to another.
I am beginner, would really appreciate if there's already a function for this.

It is not possible at least not in Sweden because the mobile operators are doing som funky routings with the ip address. Because of this it is only possible to create an outgoing connection from a mobile phone. Even if you have the mobile ip address you cant lock on and get an in going connection.
This is why there are services like Firebase, Signal and others that offer the flexibility to solve this problem
Of course some operators offers static ip adress for an extra fee, that would make it possible to run anything incoming, but users in general does not subscriber to this since they have no use for it
Look forward to if someone can prove me wrong..

I have done this with the help of a web configuration.
You will need a Web database table to save the FCM Token and username for each device.
Username can be any unique thing you can get from any registration process you want or you can hard code that as well for testing purpose but FCM Token Id must be auto Generated you can find the code how to get it form web.
Every Device FCM Token ID is attached with the username and must be unique which will be used to distinguish between all the devices in web.
Now the Process will be--
sender mobile -> Server Having all the FCM token id (and code to send notification) -> Receiver Mobile
From sender device you call the server, sending it the message and the receiver's username.
Now at server side it will search its table and find the particular FCM Token id for the specific username you have sent.
Now it will send the given message to the device of that specific token Id.
Hope this will help you!

Related

How to send notifications to specific register user through android app

I am developing a android app like GATEKEEPER , when a visitor came to apartment the operator take all details of flat owner and send a request notification to flat owner. The flat owner confirm or reject what ever it he is reply to that notification. After getting request conformation operator issue the visitor pass. I am checking the all tutorials in that everybody sending notifications to itself only please anybody knows the process explain me. Don't use firebase and any other web applications

android - when to do GCM registration

I have a android client app, a server side in django and now I am adding push notifications with GCM.
In my app I have users that login/logout, so I will have a table in my database with devices ids coupled with users, so that every time I want to notification a user, I will lookup its device id and send the notification.
my question is:
When is best to register the Device to the GCM?
When to add the Device to my Server side database?
In the Google Docs it says you should do it once, when the app is installed.
Because I have users in my app, and I want to couple a user with a device in the database, when the app is installed there still isn't a user to associate the Device with.
After the user installs the app, he can register, login and so on.
So when you think is best to register the Device to the GCM and to my server side?
Should it be with a user or only associate it later?
Thanks a lot!
My suggestion would be:
Register the device immediately after the first execution
Save device id somewhere accessible anytime by the app
Couple the id with user details after registration
With this approach you will be able to handle issues if something goes wrong with the registration process and send a notification to the device even if the user is not registered.
EDIT:
You should also implement a strategy to check on a regular basis if the association between the user and the device is still valid or needs to be updated

Android Authentication and GCM Push notifications

I'm looking to create for my app some authentication. This will basically consist of a user registering (preferably with their google account, although not necessary) and providing a username that is then sent to my server and then having the ability to log in. I then from there would like to be able for the client app to communicate with my server by sending data and receiving push notifications via GCM (google cloud messaging). It is important that the server is able to send a push notification directly to a certain user not to all registered devices.
Would someone be able to point me in the right direction for what I must do? I've had a look at a few tutorials but what I've seen has always sent messages to all registered devices not to a specific user.
Some extra information about the app:
-The client app (user) will need to send a piece of information to the server. This information will also include the user that it needs to be sent to. Once the server receives the piece of information it should send a push notification through GCM to the specified user's client app.
I'm clueless as to how I need to go about setting up the authentication system, any help would be very appreciated!
Thank you very much,
Daniel
Offcourse you can send push notifications to selected users. This process would roughly comprise the following steps:
1) send the User's GCM registration id to your own server along with a unique user id (what ever id you have assigned to that user; could be email or sim id or something like that). Save it in your database.
2) To send Push notifications to selected users, choose users from the database based on some criteria, retrieve their GCM registration ids from the database and forward them the GCM server.
but there is one important thing you must handle. GCM registration ids could change e.g if user uninstalls and re-installs the application. You must update you corresponding database entry in that case.

How should I handle authentication when my mobile apps report their device tokens to my server?

I have an app that runs across iOS and Android. I'm working to add push notifications to that app.
At a very high level, devices register with the Apple Push Notification Service (APNS) or Google Cloud Messaging (GCM) and receive a token. They then hand that token back to the server that's in charge of sending notifications. That server, when it wants to, sends a notification to APNS or GCM and says "send this notification to the devices with these tokens".
So, my apps need to be able to securely send their tokens to my server, and delete those tokens from the server when the user no longer wants to receive notifications. It's very easy to add a simple CRUD page on the server side which handles ?create=<token>, ?delete=<token>, etc.
But what happens when someone goes to my server and starts spamming random values for ?delete=<token> — it seems like they'd be able to just delete random device tokens at will?
I've thought about the "delete" case a bit more, and I think it should be easy: the app can just send along a generated public decryption key with the initial “create this token” request. That key can be stored against the token. When the app wants to delete, it can send along the encrypted copy of the token, and the server can match the token against the decrypted copy, verifying that the app must possess the stored public keys matching private encryption key (which is a secret known only to the app).
What happens when someone starts spamming random values for ?create=<token> — do they get to just fill up my database table with fake device tokens?
I can't see an easy answer — rate limiting "create" requests from any single IP address seems to be about the best we can do without registration involved. That obviously isn't going to help us against any distributed attack.
Ideally I'd like to enable push notifications by default / without the user having to "register" or anything like that. My first thought is that each device token should be tied to a known canonical Apple ID or Google account — but how do I stop users from falsifying those? Do devices come with a certificate that I can get an authoritative public key for (in which case each device can just get a row tied to its public key)? What's the best way for me to implement authentication here?
The solution to the problem for android can be found Here. In brief it can be summarised as
You use the GoogleAuthUtil class, available through Google Play
services, 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.
A lot of good questions here. :)
Let me try to break it down.
General thoughts
I don't think it's good idea to mix Android and iOS here. High level push notification architecture is similar between them, but that's about it.
Tokens are long (as I remember iOS token is uuid). So, there is no way to guess it by just randomly trying different values. So, I would say ?delete=<token> case is non existent.
The case of ?create=<token> is more realistic. First of all, somebody can bring your server to knees, registering millions of tokens. Also, if you are sending some sensitive information via push notification, you may don't want it to be received by non authorized app users.
Android solution
For Android it's easier.
As soon as you get a token on the server, just send a push message with some randomly generated string (store it in DB). Your application on a device will get this string and will send it with the token to the server (via second web call). And your server make sure that it will send anything to this token only after it was authenticated.
This way you rely on GCM ability to deliver messages to correct clients to make sure that authentication information (random string) is delivered to your application.
iOS solution
The problem with iOS is that push notification doesn't automatically trigger code execution, if the application is suspended or in background.
So, if you will try to do the same thing and a user accidentally exits your app, while push notification is being deliver than your app will never see it.
You can do following (the idea is basically the same as for Android, only with difference that we may need to require user interaction)
Push notification with a message "Please run my app and enter X" (where X is some random string)
This way, if your app is in background, a user will click on this message, enter X and your app will authenticated to the server.
In the case, if app is in foreground, it will get push payload and can authenticate directly.

C2DM - How to push messages to several devices with one sender ID?

I have one single Gmail account signed up for C2DM.
What I would like is that my app, thanks to this account (after having requested registration IDs and auth tokens for each device), could be able to provide messages to all the devices in which the app is installed.
I want to know if is it possible to use the C2DM in this way..
Thanks a lot
(for any details, just ask me.. )
ps I made the c2dm work on the emulator, but of course I cannot try what written before because I would need several phones..
Going off your question and comments, it sounds like you're just wondering if you can send c2dm notifications to an indeterminate number of devices using only one sender id.
That is exactly the way c2dm is supposed to work. You create one sender id to use on your backend servers, and that sender id is used in your app to register for c2dm notifications. Your backend then gathers all registrations ids and uses your one sender id to push notifications interested parties.
If I understood your issue correctly, the answer is: you can't.
You will have to send one http request, to google servers, for each device you want to reach.
There's no way to broadcast a message to all the users who have registered to your service.
It' frustrating because in my case I send a newsletter for all my users, so opening a connection to millions of users is expensive.
To solve the scalability issue I have created a simple appengine map-reduce task that loops through all the user registrations and create the http connection to the google services, it's the fastest you can go because it dynamically instantiate new servers for your delivery needs.
C2DM has been deprecated. GCM has replaced it, and it allows you to send messages to 1000 devices with one HTTP POST.
C2DM->GCM Migration Guide:
http://developer.android.com/guide/google/gcm/c2dm.html

Categories

Resources