Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在非OREO设备上以编程方式发出休眠通知_Android_Android Notifications_Notification Listener - Fatal编程技术网

Android 在非OREO设备上以编程方式发出休眠通知

Android 在非OREO设备上以编程方式发出休眠通知,android,android-notifications,notification-listener,Android,Android Notifications,Notification Listener,在我的应用程序中,我有一个需要在后台运行的服务。我在前台模式下启动它,这需要一个通知才能工作。我需要实现一个功能,用户可以暂停与此服务相关的通知。我使用了NotificationListenerService,其中有一个名为snoozeNotification的方法。但是这种方法需要api 26,并且只适用于oreo设备。对于非oreo设备,我认为唯一的解决方案是通知用户他可以从设置中休眠应用程序的所有通知。但此解决方案会暂停其他需要可见的通知。你还有别的解决办法吗?提前感谢。DeleteInt

在我的应用程序中,我有一个需要在后台运行的服务。我在前台模式下启动它,这需要一个通知才能工作。我需要实现一个功能,用户可以暂停与此服务相关的通知。我使用了NotificationListenerService,其中有一个名为snoozeNotification的方法。但是这种方法需要api 26,并且只适用于oreo设备。对于非oreo设备,我认为唯一的解决方案是通知用户他可以从设置中休眠应用程序的所有通知。但此解决方案会暂停其他需要可见的通知。你还有别的解决办法吗?提前感谢。

DeleteIntent:是一个PendingIntent对象,可与通知关联,并在删除通知时触发,具体操作如下:

用户特定操作 用户删除所有通知。 您可以将挂起的意图设置为aBroadcastReceiver,然后执行您想要的任何操作

 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);
在其他地方,无论何时关闭/删除通知,都可以进行监听

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

  }

您需要听一听刷卡以取消活动?谢谢您的回答!明天我会试试你的解决方案