如何创建在Android中单击时不会消失的通知? [英] How to create notifications that don't go away when clicked in Android?
本文介绍了如何创建在Android中单击时不会消失的通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int icon = R.drawable.icon4;
CharSequence tickerText = "Hello"; // ticker-text
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Hello";
CharSequence contentText = "Hello";
Intent notificationIntent = new Intent(this, Example.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
这对我不起作用.
我该如何创建一个可单击的通知,该通知可以转到我的应用程序,但是在单击时不会消失?
How could I create a notification that is clickable and goes to my app, but does not go away when clicked?
推荐答案
您应该阅读全部内容,而不仅仅是伙伴.请分步仔细阅读.
You should read the whole things not just a part, buddy. Please re-read carefully step-by-step.
// this
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon4;
CharSequence tickerText = "Hello"; // ticker-text
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Hello";
CharSequence contentText = "Hello";
Intent notificationIntent = new Intent(this, Example.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
// and this
private static final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
这篇关于如何创建在Android中单击时不会消失的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文