我的通知显示电池电量。当我关闭应用程序时,通知中的百分比不会更新其状态。我不知道我怎么能这样做现在我发布通知代码,我希望有人帮助我
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
MainActivity.this);
notificationBuilder.setOngoing(true);
notificationBuilder.setContentTitle("Battery Stats Informations");
notificationBuilder.setContentText("Battery level: " + level + "%"
+ " " + "Temp.: " + temperature + "°C");
notificationBuilder.setTicker("Informazioni batteria");
notificationBuilder.setWhen(System.currentTimeMillis());
notificationBuilder.setSmallIcon(R.drawable.icon_small_not);
Intent notificationIntent = new Intent(MainActivity.this,
MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(
MainActivity.this, 0, notificationIntent, 0);
notificationBuilder.setContentIntent(contentIntent);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification = new Notification();
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
mNotificationManager.notify(1, notificationBuilder.build());
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID,
notificationBuilder.build());
我尝试了一切但没有任何事情发生。我能怎么做?感谢