这是我工作正常的代码。如果通知从通知栏中删除,它每 20 秒显示一次通知栏,但我想每 18 秒从通知栏中删除通知,并每 20 秒再次显示一次,我该怎么办?如何删除通知表单通知栏?
public class NotificationActivity extends Activity {
AlarmManager am;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setRepeatingAlarm();
}
public void setRepeatingAlarm() {
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(20 * 1000), pendingIntent);
System.out.println("Calling Alaram...");
}
}
public class TimeAlarm extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Lokesh";
CharSequence message = "Notification Test...";
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(), 0);
Notification notif = new Notification(R.drawable.cherry_icon,
"Notification Test...", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
}
}