gpt4 book ai didi

如果其他应用程序的辅助功能服务打开,Android 辅助功能服务将无法正常工作

转载 作者:行者123 更新时间:2023-11-30 01:30:51 26 4
gpt4 key购买 nike

我正在为我的 Android 应用程序使用无障碍服务来读取来自网络运营商的弹出窗口。如果仅针对我的应用程序打开辅助功能服务,它就可以正常工作。如果我为其他一些 Android 应用打开它,onAccessibilityEvent() 根本不起作用。

list 代码:

  <service
android:name=".services.NotificationAccessibilityService"
android:exported="false"
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>

辅助功能类:

public class NotificationAccessibilityService extends AccessibilityService {


@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getClassName() != null && event.getClassName().toString().equalsIgnoreCase(
"android.app.AlertDialog") && event.getPackageName() != null
&& event.getPackageName().toString().equalsIgnoreCase("com.android.phone"))
{
Logger.d(TAG,"source info"+ " " + event.getClassName().toString());
Logger.d(TAG, String.format("onAccessibilityEvent: [type] %s [class] %s [package] %s [time] %s [text] %s",
getEventType(event), event.getClassName(), event.getPackageName(),
event.getEventTime(), getEventText(event)));
@Override
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
return super.bindService(service, conn, flags);
}

@Override
public void onInterrupt() {
}

@Override
public void onServiceConnected()
{
Intent iLaunch = new Intent(NotificationAccessibilityService.this, StatusAct.class);
iLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(iLaunch);
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK;
setServiceInfo(info);
}

private String getEventType(AccessibilityEvent event) {
switch (event.getEventType()) {
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
return "TYPE_NOTIFICATION_STATE_CHANGED";
case AccessibilityEvent.TYPE_VIEW_CLICKED:
return "TYPE_VIEW_CLICKED";
case AccessibilityEvent.TYPE_VIEW_FOCUSED:
return "TYPE_VIEW_FOCUSED";
case AccessibilityEvent.TYPE_VIEW_LONG_CLICKED:
return "TYPE_VIEW_LONG_CLICKED";
case AccessibilityEvent.TYPE_VIEW_SELECTED:
return "TYPE_VIEW_SELECTED";
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
return "TYPE_WINDOW_STATE_CHANGED";
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
return "TYPE_VIEW_TEXT_CHANGED";
}
return "default";
}

private String getEventText(AccessibilityEvent event) {
StringBuilder sb = new StringBuilder();
for (CharSequence s : event.getText()) {
sb.append(s);
}
return sb.toString();
}
}

最佳答案

我遇到了和你一样的问题。然后我通过这个定义了AccessibilityService。它至少对我有用。你应该试一试。

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagIncludeNotImportantViews"
android:canRetrieveWindowContent="false"
android:description="@string/accessibility_service_description" />

关于如果其他应用程序的辅助功能服务打开,Android 辅助功能服务将无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35776518/

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