安卓開發中實現自動點擊功能、獲取網絡信息’-博客新人初來乍到,歡迎大佬多多指教。


本人做安卓開發三個月,不是本專業的(興趣轉行),是一枚萌新,目前公司的項目是一個游戲的腳本,但畢竟一個項目所用到的知識是有限的,所以決定開通博客,堅持每天學習(目前也沒發現好的學習資源,知識比較老)並分享,這幾天將分享公司項目用到的技術同時還有自己學習的東西,請多多指教!!!

github后期同步更新!

這里實現自動點擊功能有兩種

1.自動滑動   2.自動點擊

 

自動滑動方法(參數是滑動的兩端坐標)

public void swipe(float x1, float y1, float x2, float y2){
String swipeCmd = "/system/bin/input swipe "+x1+" "+y1+" "+x2+" "+y2+" 200";
execInputCmd(swipeCmd);
}

 

自動點擊方法(參數是坐標)
public void tap(float x1, float y1){
String tapCmd = "/system/bin/input tap "+x1+" "+y1;
execInputCmd(tapCmd);
}

 

 

實現自動點擊的方式(cmd命令)
private void execInputCmd(String cmdStr){
//Log.e(TAG, "VISM:模擬觸屏命令: "+cmdStr);
try {
if(mDataOutStream==null){
Process mProcess = Runtime.getRuntime().exec("su");
mDataOutStream = new DataOutputStream(mProcess.getOutputStream());
}
Log.e(TAG, "swipeByCmd:"+cmdStr);
mDataOutStream.write(cmdStr.getBytes());
mDataOutStream.writeBytes("\n");
mDataOutStream.flush();
/*
mDataOutStream.writeBytes("exit\n");
mDataOutStream.flush();
mDataOutStream.close();
*/
} catch (IOException e) {
e.printStackTrace();
}
}

 

 

 

 

獲取手機網絡信息

1.在MainActivity中定義一個 private ConnectivityManager manager;(建議定義空間或者是manager都用private)

2.onCreate方法中初始化:

manager = this.getSystemService(context.CONNECTIVITY_SERVICE);

3.獲取網絡鏈接信息:(這里示例獲取當前wifi的情況)

State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();

將wifi toString一個就可以獲得wifi信息了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM