赶上轻扫解雇事件

赶上轻扫解雇事件

本文介绍了赶上轻扫解雇事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是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 :

  • 在用户的具体行动
  • 在用户删除所有通知。

您可以设置待定意向广播接收器,然后执行任何你想要的操作。

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
         }

  }

这篇关于赶上轻扫解雇事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:57