如何让我的Android通知一直显示直到我的应用程序关闭?

4
我已经开发了一段时间的Android,但这是我第一次尝试通知。我按照Android SDK教程中描述的方法设置了我的通知,但我不知道如何保持通知显示直到我的应用程序关闭。我想禁用通知末尾的小减号标志。我不希望用户单击通知后通知消失。我认为会有一个通知标志...但我似乎无法弄清楚这个问题。我正在开发Android SDK 2.2。我知道这是一个简单的问题,如果这个答案已经在这里了,我很抱歉...我没有找到我要找的东西。
    // Create notification manager
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    Notification notification = new Notification(R.drawable.ic_launcher, "Ready", System.currentTimeMillis());
    Intent notificationIntent = new Intent(this, HomeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    // Make a notification
    notification.setLatestEventInfo(getApplicationContext(), "Ready", "Select to manage your settings", contentIntent);
    mNotificationManager.notify(0, notification);
1个回答

5
你需要使用FLAG_ONGOING_EVENT。如果默认设置中包含FLAG_NO_CLEAR和FLAG_AUTO_CANCEL,请尝试将它们删除。

我正式承认我重新发布了一个已经有答案的问题:答案链接.....感谢jnnnnn。FLAG_NO_CLEAR是我找不到的那个。该死! - Lou Morda
notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags &= ~Notification.FLAG_NO_CLEAR; notification.flags &= ~Notification.FLAG_AUTO_CANCEL; - Lou Morda

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接