Android複製粘貼剪下板內容的一種方法

來源:互聯網
上載者:User

標籤:頁面   post   apk   broadcast   shell   sub   cat   div   read   

1 Clipper介紹

Clipper是一款簡單的app, 它可以通過一行adb shell命令來和安卓系統剪下板服務互動。

官方說明:https://github.com/majido/clipper

 

2  App下載

:clipper.apk

 

3 使用方法

 安裝App

 啟動廣播服務

adb shell  am startservice ca.zgrs.clipper/.ClipboardService

 get方法:print the value in clipboard into logs

am broadcast -a clipper.get

set方法:sets the clipboard content to the string passed via extra parameter "text"

am broadcast -a clipper.set -e text "this can be pasted now"

 

4  appium中使用的一個例子

某個安卓手機先安裝Clipper.apk

然後開啟廣播

       //執行shell命令開啟android廣播服務        Process process = Runtime.getRuntime().exec("adb -s "+udid+" shell am broadcast -a clipper.get");        InputStream is = process.getInputStream();        InputStreamReader isr = new InputStreamReader(is, "utf-8");        BufferedReader br = new BufferedReader(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");        }

其中如果有多台手機,udid為事先定義的裝置名稱

capabilities.setCapability("deviceName", udid);

若某個url資訊已在剪下板中,擷取頁面url地址

private String getUrl() throws IOException{                   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 = new InputStreamReader(is, "utf-8");              br = new BufferedReader(isr);          }catch(Exception e){              System.out.println("廣播服務出現異常");          }                    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("請啟動廣播服務");              }              url=s[1].toString().trim().substring(0, s[1].length()-1);          }catch(Exception e){              System.out.println("剪下板擷取url異常");          }          br.close();          return url;    }

 

Android複製粘貼剪下板內容的一種方法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.