gpt4 book ai didi

android - 使用 AccessibilityService 读取通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:52:31 27 4
gpt4 key购买 nike

我最近尝试使用 AccessibilityService 读取传入的通知。我知道使用 NotificationListenerService 读取通知,但这不是我需要的(为了与较低的 android 版本兼容)。我的问题是,OnServiceConnected() 永远不会被调用,即使在我的设置中,我已经为我的应用程序提供了必要的前提条件。这是我的代码:

public class NotificationAccessibilityService extends AccessibilityService{

protected void onServiceConnected() {
Log.d("Tortuga", "AccessibilityService Connected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}

@Override
public void onAccessibilityEvent(AccessibilityEvent e) {
Log.d("Tortuga","FML");
if (e.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Log.d("Tortuga","Recieved event");
Parcelable data = e.getParcelableData();
if (data instanceof Notification) {
Log.d("Tortuga","Recieved notification");
Notification notification = (Notification) data;
Log.d("Tortuga","ticker: " + notification.tickerText);
Log.d("Tortuga","icon: " + notification.icon);
Log.d("Tortuga", "notification: "+ e.getText());
}
}
}

@Override
public void onInterrupt() {
// TODO Auto-generated method stub
}
}

还有我的 XML:

AndroidManifest.xml

<service
android:name="com.tortuga.shutapp.NotificationAccessibilityService"
android:label="@string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>

<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibilityservice" />
</service>

xml\accessibilityservice.xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100" />

请帮忙,我迷路了。我目前在 Nexus 5 上运行。谢谢!

最佳答案

你开启服务了吗?在“设置-辅助功能-你的服务”

关于android - 使用 AccessibilityService 读取通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22286681/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com