如何编写一个点击时完全不做任何事情的通知? [英] 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.
在我下面的代码中,虽然 FLAG_AUTO_CANCEL 从状态栏中清除通知,但当用户单击我的通知时,他们将被带到MyActivity".
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);
推荐答案
改变
Intent notificationIntent = new Intent(this, MyActivity.class);
到
Intent notificationIntent = new Intent();
会做这项工作.要点是如果你什么都不想要,给它一个空白的意图.
would do the job. The gist is if you want nothing, give it a blank intent.
这篇关于如何编写一个点击时完全不做任何事情的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!