[英]change android notification message without stop and start service again
當我在android上啟動Service
時,這是我的Notification
方法:
private void showNotification() {
Notification notification = new Notification(R.drawable.call, "Some text", System.currentTimeMillis());
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, getString(R.string.notification_label), getString(R.string.notification_text_short), pi);
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(7331, notification);
}
以后可以更改文本嗎? 現在是例如"Some text"
,后來我想不停地更改它並再次啟動服務。
那可能嗎?
您正在使用通知ID 7331顯示通知以及啟動服務。 只要您發送具有相同ID的新通知,它就會替換舊的通知。
使用此選項更新通知
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(ns);
long when = System.currentTimeMillis();
Notification notification = new Notification("your icon", "your ticker text", when);
/*<set your intents here>*/
mNotificationManager.notify(7331, notification);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.