android - 多个状态栏通知

标签 android notifications statusbar

我能否从一个程序(服务)在状态栏中创建多个通知,或者我应该创建具有可点击对象列表(例如 LinearLayout)的新 Activity ?

最佳答案

您当然可以从一项服务或应用程序创建多个通知,但您必须问问自己,作为用户,您是否希望应用程序向您发送垃圾邮件通知。我一直在我的远程服务中使用一个通知,并通过仅更新其内容来重复使用相同的通知。这是一个例子:

public void onPlaybackStarted(int currentTrack, Show show) {
notificationManager.cancel(R.layout.notification_playing);

notification.tickerText = show.getTracks().get(currentTrack).getName();
if (notificationView == null) {
    notificationView = new RemoteViews(getPackageName(), R.layout.notification_playing);
}
notificationView.setTextViewText(R.id.notification_playing_track, show.getTracks().get(currentTrack).getName());
notificationView.setTextViewText(R.id.notification_playing_band, show.getArtist());
notificationView.setTextViewText(R.id.notification_playing_date, show.getDate());
Intent intent = new Intent(TrackPlayerService.this, ListTracksActivity.class)
        .putExtra("track", currentTrack)
        .putExtra("artist", show.getArtist())
        .putExtra("date", show.getDate())
        .putExtra("location", show.getLocation())
        .putExtra("venue", show.getVenue())
        .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notification.contentView = notificationView;
notification.contentIntent = PendingIntent.getActivity(TrackPlayerService.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.flags |= Notification.FLAG_ONGOING_EVENT;

notificationManager.notify(R.layout.notification_playing, notification);
}

如果您的通知不是循环的,这意味着您需要同时通知用户 3 或 4 件不同的事情,那么打开 ListActivity 的通知将是最好的方式。

关于android - 多个状态栏通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5435581/

相关文章:

android - 无法获取未知属性 'localProperties'

android - 如何在android中为工作日设置闹钟

Python 显示带有可见超时的通知

android - 透明状态栏覆盖 Kitkat 上的操作模式

android - 我遇到了什么样的错误?安卓定时器错误

android - 找不到 Gradle DSL 错误 mavenCentral()

error-handling - m子流的错误通知

Azure 通知中心 : The supplied notification payload is invalid

android - 如何在我的应用程序中的特定 Activity 中锁定状态栏和通知栏

android - 如何使用 phonegap 在状态栏上创建通知