我正在工作的安卓application.The应用程序就像本地短信应用程序。我面临着通知部分的问题。在原生应用中,它们通过以下方式处理通知。
1)如果消息来自特定号码,则点击通知将转到相应联系人的聊天页面,通知将被清除。
2)如果消息来自不同的号码,那么点击通知将转到主页,通知将不会清除。
我已经完成了第一部分,但我没有任何想法来做第二部分。有没有办法让通知部分不明确,并调用一个意图?
发布于 2012-09-25 20:01:55
你必须添加一个标志:
notification.flags |= Notification.FLAG_ONGOING_EVENT;下面是一个完整的例子:
private static final int NOTIFICATION_EX = 0;
private NotificationManager notificationManager;..。
在onCreate中:
notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.youricon;
CharSequence tickerText = "Sticky notification";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Sticky notification";
CharSequence contentText = "...click here and it wont go away...";
Intent notificationIntent = new Intent(this, mainmenu.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(NOTIFICATION_EX, notification);你可以随心所欲地调整自己的意图。
发布于 2012-09-25 20:03:50
您需要创建两种不同的通知,第一种是您已经实现的通知,第二种是您可以复制第一种通知并检查编号是否不同使用第二种通知,并使用包含Intent的PendingIntent中的HomeActivity将标志设置为not clear notification2.flags |= Notification.FLAG_ONGOING_EVENT;
https://stackoverflow.com/questions/12582471
复制相似问题