Android 在某些情况下,有没有办法阻止来自其他应用程序的通知?

Android 在某些情况下,有没有办法阻止来自其他应用程序的通知?,android,android-notifications,Android,Android Notifications,我正在开发一款android应用程序,它可以根据用户的位置阻止来自特定应用程序的通知,这是play store notification manager的一个扩展,下面是该应用程序的链接: 经过一段时间的研究,我找不到任何合适的API来实现这样的功能(或者我错过了一些)。我想知道如何拒绝来自某些应用程序的通知或更改其通知设置 编辑1:感谢您对实施我自己的NotificationListenerService的建议,我想获得更多关于如何实施的帮助/建议。您需要实施自己的NotificationL

我正在开发一款android应用程序,它可以根据用户的位置阻止来自特定应用程序的通知,这是play store notification manager的一个扩展,下面是该应用程序的链接:

经过一段时间的研究,我找不到任何合适的API来实现这样的功能(或者我错过了一些)。我想知道如何拒绝来自某些应用程序的通知或更改其通知设置


编辑1:感谢您对实施我自己的NotificationListenerService的建议,我想获得更多关于如何实施的帮助/建议。

您需要实施自己的NotificationListenerService

您可能希望覆盖在发布新通知时调用的方法,并在此处实现您的解雇策略:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    // Your blocking strategy here
    cancelNotification(...);
}

你需要实现你自己的

您可能希望覆盖在发布新通知时调用的方法,并在此处实现您的解雇策略:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    // Your blocking strategy here
    cancelNotification(...);
}
你可以这样做

import android.content.Intent;
import android.os.IBinder;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;

public class Block_All_Notification extends NotificationListenerService {
  @Override
  public IBinder onBind(Intent intent) {
    return super.onBind(intent);
}

@Override
public void onNotificationPosted(StatusBarNotification sbn){
    // Implement what you want here
    // Inform the notification manager about dismissal of all notifications.
    Log.d("Msg", "Notification arrived");
    Block_All_Notification.this.cancelAllNotifications();
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn){
    // Implement what you want here
    Log.d("Msg", "Notification Removed");
}
}
在您的清单文件中包括此清单文件

<service android:name=".Block_All_Notification"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action   android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>

您可以这样做

import android.content.Intent;
import android.os.IBinder;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;

public class Block_All_Notification extends NotificationListenerService {
  @Override
  public IBinder onBind(Intent intent) {
    return super.onBind(intent);
}

@Override
public void onNotificationPosted(StatusBarNotification sbn){
    // Implement what you want here
    // Inform the notification manager about dismissal of all notifications.
    Log.d("Msg", "Notification arrived");
    Block_All_Notification.this.cancelAllNotifications();
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn){
    // Implement what you want here
    Log.d("Msg", "Notification Removed");
}
}
在您的清单文件中包括此清单文件

<service android:name=".Block_All_Notification"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action   android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>


可能重复感谢您的建议,但该问题是在2013年提出的,尽管我们的问题看起来很相似,但2016年应该会有一个更新的解决方案,因为我提到的应用程序是在2014年创建的。2013年的解决方案在2014年起作用,可在2017年使用。它很可能没有被弃用,所以应该是非常感谢你的建议,但这个问题是在2013年提出的,尽管我们的问题看起来很相似,但应该在2016年有一个更新的解决方案,因为我提到的应用程序是在2014年创建的。2013年的解决方案在2014年起作用,可以在2017年使用。它很可能没有被弃用,所以应该很好。谢谢你让我知道没有内置API可以帮助我!您能再解释一下NotificationListenerService中的哪些公共方法在这种情况下特别有用吗?感谢您让我知道没有内置API可以提供帮助!请您再解释一下NotificationListenerService中的哪些公共方法在这种情况下特别有用?它不是阻止通知,只是通知是否收到任何通知,您是否找到了更好的解决方案?它不是阻止通知,只是通知是否收到任何通知,你找到更好的解决办法了吗?