With android AccessibilityService
able to paste in other app EditText
Field, but with browser testfields
(Emulator Default Browser or Samsung deault Browser) its not working, throwing error:
Cannot perform this action on a not sealed instance.
In android chrome browser with some singnup textfield its working but not for all textfields.
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
if (source != null && ( event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED ) ) {
// || event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED ) &&
//event.getClassName().equals("android.widget.EditText")
//) {
ctx = getApplicationContext();
ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", "XYZ");
clipboard.setPrimaryClip(clip);
source.performAction(AccessibilityNodeInfo.ACTION_PASTE);
//Not Working, always return false.
//Tried with other options
Bundle argumentsTest = new Bundle();
argumentsTest.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "Bundle Test Data");
source.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT,argumentsTest )
// Not Working, throw java.lang.IllegalStateException exception
//Message: "Cannot perform this action on a not sealed instance"
}
}
I don't beleive you're trying to do what you think you're trying to do.
When you set the "text" of an accessibilityNodeInfo, what you're chaning is the text property of that object, as it pertains to your accessibility service. THIS DOES NOT mean, that you are changing the text of the EditText box, that the accessibilityNodeInfo object references. By the time your accessibility service gets this object, the two objects are quite separate from each other. Even if your code were to run successfully, you would not be getting the results you are expecting. Now, as for why you cannot perform this action, knowing this it should be obvious. For an accessibility service to be able to modify the nodes it has, doesn't really make sense. So they become sealed (think of this as a run time enforcement of a constant). Accessibility nodes become sealed and unsealed at various points in their lifetime. The parts of the framework that have access to unsealed node infos are View classes and private APIs. Any accessibility service related tasks are going to be dealing with sealed, read-only instances.
As for why your original solution is not working, I believe that we do not have enough information. The "ACTION_PASTE" approach is (approximately) the correct approach, HOWEVER, there are an abundance of issues when doing so with web browsers. Browser version, Android version, device version, website, etc all play a role. Especially if your set up is old enough to not use the new WebView (pure chromium webview, rather than the old 4.+ approach of odd embedded mobile WebViews based on outdated versions of WebKit, which will now never be updated). I recommend testing your code on an up to date Nexus device, using at least Android 5.0 and seeing if your code works. If you cannot do this, report version information for your set up. If you already are, on what website?