How to Program Android Notification?

1.2k Views Asked by At

I had developed a news app for android phones. Every day there will new articles. I am using a hosting for storing articles and my app use webview to load these information. Now my question is that how to program notification (without using third party service) so that when a new articles is published my app should generate a notification on android notification bar.

4

There are 4 best solutions below

0
On

Here are some good implementation of Google Cloud Messaging

androidexample.com

www.androidhive.info

Also you can use RSS feed for this kind of functionality, specially where data is changed frequently.

For notifications you can follow my repository here I have tried to make all possible types of notifications Android Notification Examples

0
On

You should take a look to the Service class, http://developer.android.com/guide/components/services.html

built in the Android frame work as an independent thread (no visible for the user), this can bring you the posibility to run a task in the android background services when the device is started, this should contain the code with the URI's that gets the articles from the host you are talking

After this you should start by checking the Notification class http://developer.android.com/reference/android/app/Notification.html

it's pretty easy to send signals to android to notify to the user the info you want to display, this subclass make it still more easy Notification.Builder

here's an example

 Notification noti = new Notification.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .build();
0
On

This is a complicated answer. To display a notification, there is NotificationManager and many options for what, when and how to display content.

But, since your information is managed remotely, you need a push service to notify your app of what needs to be displayed and when to display it.

Google Cloud Messaging (GCM) is a great third party solution. However, if you want to implement your own, then you are talking about setting up a long-polling TCP service that is very complicated. You may want to at least use something like XMPP and associated libraries to get started. But even that is only very basic...

You will need the device to register to a server to "listen" for events. Your server will need to handle those connects, and also post events. You will need to handle message queuing because phones go offline. Those are the parts that GCM handles.

After that, you will need authentication policies if you want individualized content (and who doesn't?). If your app is popular, you will need distributed servers, etc. just to handle registrations, subscription requests and changes. You will probably also want server-saved user settings (for multiple devices or for when users get new phones). You may also want users to setup accounts with Facebook or LinkedIn, which you then have to handle. I've built a basic service using GCM and the rest of this is a ton of work.

There are many third party services that are essentially free to small companies/projects. Like Parse or QuickBlox.

0
On

You should look into Google Cloud Messaging (GCM). You will need to setup both server and client to make this work. General step would be. 1. Register a project with google for GCM. 2. Your app needs to register the device to the project using gcm api. 3. On server, when you have new content, using Gcm server api send message. 4. On your app, when you receive the gcm message, trigger your notification to launch the app.

https://developers.google.com/cloud-messaging/android/