我写了一些Android代码来显示图标。但是,运行代码后,图标可以显示但不会消失(显示关闭)。它总是在通知栏上。如果可能的话,你能帮我看一下吗? THX
final Notification.Builder mBuilder = new Notification.Builder(getApplicationContext());
final NotificationManager mNotifyManager =
(NotificationManager) getSystemService(
Context.NOTIFICATION_SERVICE);
final int mNotifyId = 1;
final String TITLE = "abc";
final String MSG = "abc is active.";
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_notification);
mBuilder.setContentTitle(TITLE)
.setContentText(MSG)
.setSmallIcon(R.mipmap.ic_dark)
.setLargeIcon(largeIcon)
.setOngoing(true)
.setAutoCancel(false);
final Handler handler= new Handler();
final Runnable r = new Runnable() {
public void run() {
mNotifyManager.notify(mNotifyId, mBuilder.build());
mNotifyManager.cancel(mNotifyId);
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);