90

サービスが終了すると(成功または失敗)、アンドロイド通知を使用してユーザーに警告し、プロセスが完了したらローカルファイルを削除したいと考えています。

私の問題は、失敗した場合に、ユーザーに「再試行」オプションを許可したいということです。そして、彼が再試行せずに通知を却下することを選択した場合、プロセスの目的で保存されたローカルファイル(画像...)を削除したいと思います。

通知のスワイプして閉じるイベントをキャッチする方法はありますか?

4

3 に答える 3

149

DeleteIntent : DeleteIntent は PendingIntent オブジェクトであり、通知に関連付けることができ、通知が削除されたときに起動されます。

  • ユーザー固有のアクション
  • ユーザー すべての通知を削除します。

保留中のインテントをブロードキャスト レシーバーに設定してから、必要なアクションを実行できます。

  Intent intent = new Intent(this, MyBroadcastReceiver.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);
  Builder builder = new Notification.Builder(this):
 ..... code for your notification
  builder.setDeleteIntent(pendingIntent);

MyBroadcastReceiver

public class MyBroadcastReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
             .... code to handle cancel
         }

  }
于 2013-02-03T10:39:51.530 に答える