1. ホーム
  2. android

[解決済み] スワイプによるイベント解除をキャッチする

2023-03-22 18:54:53

質問

サービスの終了(成功または失敗)を知らせるためにアンドロイドの通知を使っているのですが、処理が終了したらローカルファイルを削除したいのです。

私の問題は、失敗の場合に - 私はユーザーに "再試行" オプションを知らせたいことです。そして、もし彼が再試行しないことを選び、通知を解除する場合、私はプロセスの目的のために保存されたローカルファイル(画像・・・)を削除したいです。

通知の swipe-to-dismiss イベントをキャッチする方法はありますか?

どのように解決するのですか?

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

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

Pending IntentをブロードキャストReceiverに設定し、任意のアクションを実行することができます。

  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
         }

  }