One way to copy and paste clipboard content on Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.