Simple notification in Android

package com.notification;

 

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

 

public class NotificationActivity extends Activity {

private NotificationManager manager;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

       Notification notifydetails=new Notification(R.drawable.ic_launcher, “new alert”, System.currentTimeMillis());

       Intent i=new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(“http://www.google.com”));

       

       PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, i, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

       notifydetails.setLatestEventInfo(getApplicationContext(), “title”, “this is text”, pi);

       manager.notify(0, notifydetails);

        

        

    }

}

 

when we click on the button it navigates to the browser and loads the url given with the implicit intent.

 

 

Advertisements

One thought on “Simple notification in Android

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s