3

5 秒後に消える通知バーに通知を作成するにはどうすればよいですか? 例えば; これは通知コードです:

Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
        .setContentTitle("Notification")
        .setContentText("This is a notification that didsappears in 5 seconds")
        .setSmallIcon(R.drawable.icon)
        .setContentIntent(pIntent)
        .addAction(R.drawable.icon)


NotificationManager notificationManager = 
  (NotificationManager) getSystemService(NOTIFICATION_SERVICE);


notificationManager.notify(0, noti);

このコードから始めて、5 秒後に消える通知を作成するにはどうすればよいですか?

4

2 に答える 2

1

メソッドcancel(int id)またはcancelAll()を使用して、通知を閉じることができます。タイマーを 5 秒間開始し、終了したら cancel(); を呼び出します。 http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)

于 2013-07-15T14:02:31.457 に答える