【问题标题】:Android: Detecting events on the notification barAndroid:检测通知栏上的事件
【发布时间】:2015-06-17 09:40:34
【问题描述】:

有没有办法检测通知栏上的事件,比如向左或向右滑动?

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    看到这个http://stackoverflow.com/questions/14671453/catch-on-swipe-to-dismiss-event

    它使用 DeleteIntent。 DeleteIntent:DeleteIntent 是一个 PendingIntent 对象,可以与通知相关联,并在通知被删除时触发,ether by :

    用户特定的操作 用户删除所有通知。 您可以将 Pending Intent 设置为广播接收器,然后执行您想要的任何操作。

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

    .....通知的代码 builder.setDeleteIntent(pendingIntent); 我的广播接收器

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

    【讨论】:

    • 谢谢,我确实看到了,但我对删除通知或通知状态不感兴趣,无论如何,我想捕捉确切的滑动事件及其方向。
    • 为什么要知道它被刷到了哪个方向?
    • 我想向左滑动添加一个动作。
    猜你喜欢
    • 2013-06-17
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    相关资源
    最近更新 更多