在我的应用关闭之前,如何显示Android通知?

时间:2012-01-17 02:14:03

标签: android notifications notificationmanager

我已经为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 个答案:

答案 0 :(得分:5)

你想要FLAG_ONGOING_EVENT。如果它们是默认值的一部分,请尝试删除FLAG_NO_CLEAR和FLAG_AUTO_CANCEL。