harveyslash
harveyslash

Reputation: 6012

Correct way to send push notifications

I want to send a notification from some server to android device. The most obvious(and power-hungry) way is to keep searching some database for any new messages using a service/broadcast receiver.

I am sure there are other ways to get this job done. I took a look at GCM(google cloud messaging) , and it seems that google always keeps some TCP/IP connection active. This essentially means that using GCM will use less power.

However, I have a few questions regarding GCM.

  1. Does a user NEED to have google services, and a registered play id ?
  2. If a user side-loads an apk, will he still be able to receive notifications ?

I would like to know if there are alternatives to GCM

What about devices running forked android versions, like nokia X , kindle etc? How are push notifications sent to those devices ?

Upvotes: 0

Views: 716

Answers (1)

CarlesCF
CarlesCF

Reputation: 205

Does a user NEED to have google services, and a registered play id ?

Yes, it is necessary to use Google Play Services in your development. However users do not need to have a Google account or the Google Play Services Installed.

If a user side-loads an apk, will he still be able to receive notifications ?

Yes.

The steps that must be followed to send a notification to a device are:

  1. Developer creates application in Google Developer Console
  2. User installs application
  3. Application gets a NotificationID and sends it to your database
  4. You store the NotificationID at your servers with any other information related (your username, device info, etc.)
  5. Whenever you want to send a Notification you connect to GCM sending one or more NotificationID and the notification content.
  6. The users related to the NotificationID will receive in your Application the notification content.
  7. Do any action you need.

Have a look here.

IMHO there is not any real alternative to GCM in Android (based on efficiency and simplicity). You may look for 3rd party services that will help you in the implementation and add value (marketing, business intelligence). As an example of this take a look to UrbanShip.

If you want to implement your own solution you should have a look to WebSockets. This will mantain an active communication between your server and the device. Those sockets are thought for real time communication between your server and the mobile.

Two issues:

  • How is the application affecting the battery depends on your implementation and the application use-case (how frecuent are you sending information, how long is the connection stablished).
  • I am not aware of any native implementation of this in Android but there are a few Libraries coming from open source projects. Google it.

Upvotes: 1

Related Questions