public class TestService extends AccessibilityService {
String text;
Context context;
TestService(String text,Context context){
this.text=text;enter code here
this.context=context;
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Toast.makeText(context,"helo",Toast.LENGTH_LONG).show();
AccessibilityNodeInfo source = event.getSource();
if (source != null && event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED && event.getClassName().equals("android.widget.EditText")) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", text);
clipboard.setPrimaryClip(clip);
source.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}
}
@Override
public void onInterrupt() {
}
}
我用它将我的剪贴板文本复制并粘贴到我当前文本光标所关注的位置,但它不起作用?我是这种无障碍服务的新手