Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a notification that does absolutly nothing when clicked?

Ive seen many examples of how to make something happen when the user clicks on a notification but I actually don't want anything to happen. If the user clicks on the notification I want the notification to simply dissapear and the user NOT taken anywhere.

In my code below, while FLAG_AUTO_CANCEL clears the notification from the status bar, when the user clicks on a my notification they are taken to "MyActivity".

How can I create a notification that does nothing?

Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis());

        //Define the expanded message and intent
        Context context = getApplicationContext();
        CharSequence contentTitle = res.getString(R.string.messages_sent_ellipsis);


        Intent notificationIntent = new Intent(this, MyActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0 );
        notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        //Pass the notification to the notification manager
        mNotificationManager.notify(1, notification);
like image 536
Mel Avatar asked Oct 07 '11 01:10

Mel


1 Answers

Changing

Intent notificationIntent = new Intent(this, MyActivity.class);

to

Intent notificationIntent = new Intent();

would do the job. The gist is if you want nothing, give it a blank intent.

like image 155
PH7 Avatar answered Sep 23 '22 00:09

PH7