抓住滑动以关闭事件 [英] catch on swipe to dismiss event

查看:19
本文介绍了抓住滑动以关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android 通知在服务完成(成功或失败)后提醒用户,并且我想在该过程完成后删除本地文件.

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 problem is that in the event of failure - I want to let the user a "retry" option. and if he chooses not to retry and to dismiss the notification I want to delete local files saved for the process purposes (images...).

有没有办法捕捉通知的滑动关闭事件?

Is there a way to catch the notification's swipe-to-dismiss event?

推荐答案

DeleteIntent:DeleteIntent 是一个 PendingIntent 对象,它可以与通知关联,并在通知被删除时被触发,以太:

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

  • 用户特定操作
  • 用户删除所有通知.

您可以将 Pending Intent 设置为广播接收器,然后执行您想要的任何操作.

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
         }

  }

这篇关于抓住滑动以关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆