【发布时间】:2016-07-22 10:26:42
【问题描述】:
在我的应用中,我添加了一个持续通知。通知在状态栏上有一个图标,在通知区域中有更多详细信息。
这张图片来自谷歌。这是通知区域:
我需要状态栏上的图标始终保持在那里,但用户将能够在通知屏幕中关闭通知,这样用户将只停留在状态栏上的图标上。 我该怎么做?
我的服务代码:
@SuppressWarnings("static-access")
@Override
public int onStartCommand(Intent intent, int flag, int startId)
{
super.onStartCommand(intent, START_STICKY, startId);
...
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.myNotificationString))
.setContentText(string1 + " | " + string2)
.setLargeIcon(appIcon)
.setSmallIcon(getResources().getIdentifier("icon_" + getCurrentIconNumber(),"drawable", getPackageName())); // the icon changes every day
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0 ,resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(myRequestCode, notification);
return START_STICKY;
}
【问题讨论】:
-
对不起,但对我来说,这个问题还不清楚
-
我编辑了。简而言之:假设我有一个向用户显示电池状态的应用程序。用户希望在状态栏上看到电池状态,但又不想一直在通知区看到它作为通知。所以我希望用户能够在通知区域关闭通知,但状态栏上的图标不会消失。
-
喜欢闹钟活动通知吗?您可以删除已设置警报的通知,但如果删除它,您将始终在状态栏中看到应用程序图标。我明白了吗?
-
我想是的.. 如果我理解你
标签: android notifications