Android - Code design of notification feature - java

I am working on an Android social app. It contains notification feature such as when A send a friend request to B, B should later get a notification icon shows 1 friend request on App bar (not a toast).
In order to know if the user has a friend request or not, the app will need to periodically send HTTP request to my backend API query for any notification. This should be performed in background. I am not sure what is a good way of implement such a feature. Should I use a Android Service? or should I spin a thread by myself? How to design and implement this to make sure it won't drain the data and battery? If I want to add a toast feature later, how should I design the whole client side notification system to make sure its easy to add the toast functionality?
Code pointers or suggestions will be greatly helpful. Thank you!

Periodically sending web-requests to check whether the user has any notifications or not is very expensive task for battery life.
Rather I suggest to use Push Notifications. There are third-party libraries available for this. Also recently Google Cloud has started Google Cloud Messaging for Android which is powerful framework to sync data between devices for specific app on certain events.
http://developer.android.com/google/gcm/index.html
Please follow the link above for more information to use Google Cloud Messaging for Android.
Also please have a look at following framework. It may of your interest.
https://parse.com/tutorials/android-push-notifications
sending web-requests periodically is even more expensive task (for battery) when the internet is not available in the device.

Related

is it possible to make push notifications to all devices which had installed my application without Firebase Cloud Messaging (FCM)?

I want make a push notification when there is data insert to table of the database. I use REST API in android using retrofit. Could it possibly to make push notification every "insert" to all devices without firebase cloud messaging???
FCM is just a framework that allows you to send push notifications. I know that Samsung has their own framework that they use. And maybe there are others.
So, technically it's possible to create your own framework to do this, but I would never recommend it. There is so much to consider to get this done correctly (power use, security, registration of devices, etc. etc.) and using FCM is quite easy.

What is the best way to send android notification

I am making an android app and I need to send notifications across devices. For example, A performs an action and B will be notified about the A's action.
I have also WebSocket with background services but the battery doesn't like..
What is the best practice to do this?
And whats about firebase?
Thank you
The best practice is to use Push Notification. Firebase provides an excellent support to implement Push Notification. Please refer this for more information:
https://firebase.google.com/docs/cloud-messaging/

Android Push Notifications on Android Device that can not install Google Play Services

I have a Android Device that does not have Google Play Services on it and can not because it is not a certified device.
I am looking for a way to send Push Notifications to this device to wake it up and process an incoming message.
We have the ability to customize the Android BSP (ASOP) if there is any possible way to create our own custom Push Notification server to accomplish this?
Yes there is. Just the other day I had the same question. My scenario involved real time notifications though. Everything is updated in real time . and the idea of using web sockets came to me. And luckily I knew socket.io , luckily android had a native build with gradle. Consider researching into this concept.
Right off the bat. Features like back off time checks, back pressure and timeouts.

Implementing status update for android

I am developing an android application that is connected to a restful API.
There is a challenging situation that the user of the app changes a setting on the website that should be changed on the android app too...
but I don't know how to notify the android app about the recent change made on the server.
can you help me solve this problem?
I was thinking about a push notification. is it a good practice to do so?
thank you for your time...
One way is to use Google Cloud Messaging to send a push notification, another way is occasionally poll server for updates. Obviously first way is better because GCM batches that polling for all apps that use it => less battery drain etc.
In your case you probably also want to poll server for settings right before showing them in the app.

Asynchronous android GAE communication using restlet

I would like to repeatedly (every second) ask for the message (object or value) to GAE (if android client did not create or change something there) from another android device. I need to check it pretty fast, but I know that it happens aproximately once in hour.
I use restlet and I don't want to create new thread and poll by get from this thread every second, because this is very battery consuming. I also don't want to use C2DM.
Is it somehow possible to do this? I have found something about NIO nonblocking http connectors here:
http://restlet-code.1609877.n2.nabble.com/Push-data-from-server-using-a-live-HTTP-connection-td2906563.html
But here is described only the client side and I also don't know if this solution would even be possible to use on GAE and how. Does anyone know more about this approach?
Thank you very much in advance.
As the author of uniqush, I created an entry in the FAQ page specific to this question.
Can I use uniqush on Google App Engine?
Yes and no.
If you just want to use GCM on Google App Engine, then there are some code in uniqush-push which you can directly use.
However, because Google App Engine does not support socket connection, there is no way to use APNS. In another work, if you want to setup a server on Google App Engine, you cannot push any notification to iOS devices no matter what software/library you are using.
I did considered to port uniqush to Google App Engine. But because of this fact, I think it may be better to port it until Google let us use client-side socket connections, or provide some way to connect to APNS server.
Again, if you are considering to use Google App Engine as a server for your App, please be aware that you will not be able to push notification to any iOS device right now. If this fact does not bother you, then do it.
Personally, I recommend you to run a server with full control. It is not expensive nowadays. Amazon EC2 or similar cloud products may be a good choice to run uniqush.
As I recommended above, using a (virtual) server with full control would be a better choice if you want to support more platforms besides Android.
If there is any other question, please feel free to reply.
For being future proof I would suggest you have a single push notification service for both kind of devices. You can either build on your own, or leverage something like uniqush or this
Also the Urban Airship's SDK would be a good option to look at, more details here
this is similar to Urban Airship but only a fraction of the cost. The API allows you to send a C2DM message to a user via a call. After you implement the broadcast reciever, when a user installs the app they are prompted to accept the message. If they accept a token is sent to the C2DM server identifying the user. This token is then used to send them a message via the C2DM platform. The Zend PHP Framework has built in functions for this but if reliability is a concern go with an external provider like Remote Queries or Urban Airship

Categories

Resources