问题描述
我试图填补使用像DashLane或使用辅助服务的一些其他应用程序可访问服务的EditText申请。我用事件视图集中。当EditText上得到集中的情况下起步,但的getSource()返回null。
code是:
AccessibilityNodeInfo源= event.getSource();
如果(来源!= NULL){
ClipboardManager剪贴板=(ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData夹= ClipData.newPlainText(标签,测试数据);
clipboard.setPrimaryClip(夹);
source.performAction(AccessibilityNodeInfo.ACTION_PASTE);
Toast.makeText(MyAccessibilityService.this,粘贴成功,Toast.LENGTH_LONG);
}
和我尝试了一些的是给错误的其他方法。所以这里有一个问题是,为什么它返回null。任何人都可以请帮我。
Androidmanifest
<使用-权限的Android:名称=android.permission.BIND_ACCESSIBILITY_SERVICE/>
<使用-权限的Android:名称=android.permission.SYSTEM_ALERT_WINDOW/>
<应用
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:权限=android.permission.BIND_ACCESSIBILITY_SERVICE>
<服务机器人。MyAccessibilityService名称=机器人:标签=@字符串/ APP_NAME机器人:启用=真正的机器人:出口=真正的>
<意向滤光器>
<作用机器人:名称=android.accessibilityservice.AccessibilityService安卓资源=@ XML /辅助功能/>
&所述; /意图滤光器>
Accessibility.xml
<辅助服务的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:说明=@字符串/ accessibility_service_description
机器人:packageNames =com.test.toasts2
机器人:accessibilityEventTypes =typeAllMask
机器人:accessibilityFlags =flagDefault
机器人:accessibilityFeedbackType =feedbackSpoken
机器人:notificationTimeout =100
机器人:canRetrieveWindowContent =真
机器人:settingsActivity =com.example.android.accessibility.ServiceSettingsActivity
/>
您错过了在清单文件中的元标记。只需添加。
<元数据的android:NAME =android.accessibilityservice
机器人:资源=@ XML /无障碍>
i am trying to fill EditText filed using accessibility service like DashLane or some other apps which are using accessibility Service. i am using an event view focused. when EditText gets focused the event getting started but getSource() returns null.
Code is:
AccessibilityNodeInfo source = event.getSource();
if (source != null) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "TEST DATA");
clipboard.setPrimaryClip(clip);
source.performAction(AccessibilityNodeInfo.ACTION_PASTE);
Toast.makeText(MyAccessibilityService.this, "Pasted Successfully", Toast.LENGTH_LONG);
}
and i tried some of the other methods which is giving errors. so one question here is why its returning null. can anyone pls help me out.
Androidmanifest
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<service android:name=".MyAccessibilityService" android:label="@string/app_name" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" android:resource="@xml/accessibility" />
</intent-filter>
Accessibility.xml
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/accessibility_service_description"
android:packageNames="com.test.toasts2"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"
/>
You missed the meta tag in manifest file. just add.
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/accessibility">
这篇关于event.getSource()返回的android空无障碍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!