15

I need to create a notification,which will display in the top but it should not navigate to any page,should not have any onclick function.

here is the code which i have used.

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.icon,"Notification!", System.currentTimeMillis());

Context context = getApplicationContext();

String notificationTitle = "Message";
String notificationText = Msg;
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(myBlog), context, com.gurupro.LiveChat.class);

myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TOP);




//PendingIntent pendingIntent = PendingIntent.getActivity(Home.this,    0, myIntent, 0);



myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

//myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;



myNotification.setLatestEventInfo(context, notificationTitle,notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);

Could anybody help me.@thanks

1 Answers1

32

Use Intent wihtout having component, like below

PendingIntent contentIntent = PendingIntent.getActivity(
    getApplicationContext(),
    0,
    new Intent(), // add this
    PendingIntent.FLAG_UPDATE_CURRENT);

This is provide a way where use can't open an Activity.

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186