通过代码获取所有Android棒棒糖通知
我想为高通Toq Smartwatch制作一个通知小程序。它有一个预构建的,但它不能与Android棒棒糖一起正常工作,所以我决定自己创建一个。我读过关于使用无障碍服务的文章,但它对我不起作用。有人能找到我的代码有什么问题吗?我仔细检查并为该服务启用了“设置>可访问性”,因此这似乎不是问题所在 Android清单:通过代码获取所有Android棒棒糖通知,android,android-service,android-notifications,Android,Android Service,Android Notifications,我想为高通Toq Smartwatch制作一个通知小程序。它有一个预构建的,但它不能与Android棒棒糖一起正常工作,所以我决定自己创建一个。我读过关于使用无障碍服务的文章,但它对我不起作用。有人能找到我的代码有什么问题吗?我仔细检查并为该服务启用了“设置>可访问性”,因此这似乎不是问题所在 Android清单: <service android:name=".ToqAccessibilityService" android:label="@string/serv
<service android:name=".ToqAccessibilityService"
android:label="@string/service_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>
}
配置xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="100"
android:description="@string/accessibility_service_description"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="false"/>
如果我将“typeAllMask”的“typeNotificationStateChanged”更改为“typeAllMask”,我将获得所有类型的点击和窗口事件,但没有一个关于通知的事件。有人知道我的代码中有什么错误吗?我知道有很多类似的问题,但我没有在这些条目中找到任何解决方案
提前非常感谢 我找到了解决这个问题的办法。我没有使用AccessibilityService,而是使用NotificationListenerService Android清单:
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
最后,您必须输入“设置>声音和通知>通知访问”,并使您的应用程序能够访问通知
通过这种方式,我成功地在创建和删除时获得了通知
如果有人使用AccessibilityService达到了同样的效果,请发布一个答案。感谢CitoPaez提供了这个有用的答案。我在Android L易访问性服务中也面临同样的问题。再次感谢你
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
public class NotificationListener extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Notification n = sbn.getNotification();
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Notification n = sbn.getNotification();
}
}