简体   繁体   中英

Send a data from server to the specific android device

I'm new to Android so I'm looking for the best approach to send text/data from a server (webservice) to one specific android device at a time (each time to another user). The steps are:

  1. Webservice receives a json from the application, a logged in user ones in a time (pretty simple);
  2. The Server processes received data and sends it to the one specific user\\device. Each time the server receives the data it follows the message to another user.
  3. Currently the user is an android app owner. The next step - the user can use another platform app and I register on the Server what kind of device sent/should receive the data.
  4. If user was offline the message should be removed form the waiting list and has to be sent to another user that is online.

The main problem for me is to define how do I send a data to the specific user - by ID\\username , device ID, other? I tried to practice GCM but it seems not exactly what I'm looking for because I'm planning to use the same server to send data not only to android devices but to iphone/windows as well. Thank you.

For android, you should use GCM. For other platforms, they should have their Push Messaging api on its own.

So, when a phone registers with GCM, you will get a handle which you will communicate to your server. When you store this handle in a database or something, also keep the kind of phone (Android, iOS, etc).

When you want to notify the user, check which kind of store it is and implement different protocols for different platforms.

There might be some library that abstracts this away too but I don't know any .

Edit: I've found some

You may want to check Urban Ship (commercial), PushSharp a server-side library to let you send push notifications to many platforms or yet and alternative: StackMob . Just google for more options if neither please you.

There is no way to contact devices directly from your server

  • device may be not accessible
  • device in carriers walled garden and has no outside IP address ( almost always )

Your only kind of push solution is cloud messaging. Alternatively you can implement folowing schema:

  • all devices have unique ID
  • devices poll server with regular interwals to see whether there is something for them

If you like to have "offline"-mode, you may consider message expiration ( say, your poll interwal is 5 minutes so expire all messages not retrieved inside 10 minutes )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM