。 我想通过我的应用程序访问另一个应用程序中的编辑文本。 因为我想在其中编辑 我尝试广播,但我现场
答案 0 :(得分:0)
您可以尝试AccessibilityEvent
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.e("-onAccessibilityEvent-", "----------");
AccessibilityNodeInfo source = event.getSource();
if (source1.getClassName().equals("android.widget.EditText")) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label","android");
clipboard.setPrimaryClip(clip);
source1.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}}
您需要在onServiceConnected
中注册public void onServiceConnected() {
Log.e("-onServiceConnected-", "----------");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT |
AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS |
AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY |
AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS |
AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS |
AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS |
AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS;
info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
setServiceInfo(info);
}