当我在
android上启动Service时,这是我的通知方法:
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,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); }
以后可以更改文本吗?现在是例如“一些文本”,后来我想不停地更改它并再次启动服务.
那可能吗?
解决方法
您正在使用通知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);