0

我想显示一个正在进行的通知。但它仍然显示在通知部分。我为我的通知使用了自定义布局。

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = android.R.drawable.alert_dark_frame;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, "Hi", when);
    RemoteViews contentView = new RemoteViews(getPackageName(),
            R.layout.custom_notification);
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    notification.contentIntent = contentIntent;
    notification.defaults |= Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(0, notification);
}

编辑:你可以看到这张图片,看看我想要做什么。 http://backcountrynavigator.com/wp-content/uploads/screenshots/download_ongoing_notification.png

4

1 回答 1

0

你应该开始持续的通知,Service.startForeground()除了NotificationManager.notify()

编辑:我还建议您使用 Notification.Builder 而不是 new Notification(),然后使用setOngoing(),只是为了保持清洁。

于 2013-10-17T15:47:43.443 回答