1 Clipper Introduction
Clipper is a simple app that can interact with the Android Clipboard service through a single line of adb shell commands.
Official Note: Https://github.com/majido/clipper
2 App Downloads
:clipper.apk
3 How to use
Install the App
Start the broadcast service
ADB shell am startservice ca.zgrs.clipper/. Clipboardservice
Get method: Print the value in Clipboard to logs
Am Broadcast-a Clipper.get
Set method: Sets the Clipboard content to the string passed via extra parameter "text"
" This can is pasted now "
4 An example used in Appium
One Android phone first installs clipper.apk
Then turn on the radio.
//Execute shell command to turn on Android broadcast serviceProcess process = Runtime.getruntime (). EXEC ("adb-s" +udid+ "Shell am broadcast-a clipper.get"); InputStream is=Process.getinputstream (); InputStreamReader ISR=NewInputStreamReader (IS, "Utf-8"); BufferedReader BR=NewBufferedReader (ISR); String Urlstr=""; String Line=""; while(line = Br.readline ())! =NULL) {Urlstr+=Line ; } if(Urlstr.contains ("result=0") {runtime.getruntime (). EXEC ("Adb-s" +udid+ "Shell am startservice ca.zgrs.clipper/. Clipboardservice "); }
If there are multiple phones, Udid is a pre-defined device name
Capabilities.setcapability ("DeviceName", Udid);
If a URL message is already in the Clipboard, get the page URL address
PrivateString GetUrl ()throwsioexception{String url= ""; BufferedReader BR=NULL; Try{Process Process= Runtime.getruntime (). EXEC ("adb-s" +udid+ "Shell am broadcast-a clipper.get"); InputStream is=Process.getinputstream (); InputStreamReader ISR=NewInputStreamReader (IS, "Utf-8"); BR=NewBufferedReader (ISR); }Catch(Exception e) {System.out.println ("Broadcast Service Exception"); } Try{String Urlstr=""; String Line=""; while(line = Br.readline ())! =NULL) {Urlstr+=Line ; } string[] s=NULL; if(Urlstr.contains ("data=\" ") ) {s=urlstr.split ("Data=\" "); } Else{System.out.println ("Please start the broadcast service"); } URL=s[1].tostring (). Trim (). substring (0, S[1].length ()-1); }Catch(Exception e) {System.out.println ("Clipboard get URL Exception"); } br.close (); returnURL; }
One way to copy and paste clipboard content on Android