catch on swipe to dismiss event

前端 未结 3 1316
耶瑟儿~
耶瑟儿~ 2020-11-27 12:22

I\'m using an android notification to alert the user once a service is finished (success or failure), and I want to delete local files once the process is done.

My p

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 12:31

    DeleteIntent: DeleteIntent is a PendingIntent object that can be associated with a notification and gets fired when the notification gets deleted, ether by :

    • User specific action
    • User Delete all the notifications.

    You can set the Pending Intent to a broadcast Receiver and then perform any action you want.

      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
             }
    
      }
    

提交回复
热议问题