利用ADB實現無線串連安卓裝置

來源:互聯網
上載者:User

標籤:android   class   blog   http   java   tar   

昨天用C++寫了個命令列工具,我在Linux下用g++編譯的。可以實現無線ADB快速串連安卓裝置,不過其他平台需要重新編譯原始碼。

要求電腦已經把adb 添加到系統內容變數中,安卓裝置擷取root許可權並開啟無線調試,推薦使用adbWirless。

 

在shell 中輸入以下命令都可以串連到 192.168.1.10 裝置上,並列出當前已經串連的裝置

$AndroidConnector -c 192.168.1.10$AndroidConnector 192.168.1.10
$AndroidConnector -c 1.10
$AndroidConnector 1.10

 

在shell中輸入以下命令可以斷開已串連的裝置並列出當前已經串連的裝置

$AndroidConnector -d 192.168.1.10$AndroidConnector -d 1.10

 

你可以在shell 中輸入以下命令來查看協助文檔

$AndroidConnector --help

  

以下是該命令列工具的原始碼,需要自行編譯。

/******************* AndroidConnector *************************//*       By Geequlim                    *//**************************    2014   *****************************/#include <iostream>#include <string>#include <cstdlib>#include <cstring>using namespace std;///show informations bool showInfo(const char* arg){if(strcmp( arg,"--help" )==0)//show help{cout<<"Wirless adb helper \n""NOTIC:\n""     You must keep debugable for you Android device first!\n""     Your system should added the adb to the PATH!\n\n"" To connect device:\n""-c ip ( $AndroidConnecter -c 192.168.1.10 ) \n""    or the device ip  ( $AndroidConnector 192.168.1.10  )\n\n"" To disconnect device:\n""-d ip ( $AndroidConnector -d 192.168.1.10 )\n\n"" To disconnect all devices:\n""-d all\n""-d\n\n""If your the ip starts with \"192.168\" : \n""   ($AndroidConnector -d 1.10)\n"  " It is the same  as ($AndroidConnector -d 192.168.1.10 )\n"<<endl;return true;}else if( strcmp(arg,"--version")==0)//show version{cout<<"AndroidConnector  0.1.1\n""Copyright (C) 2014 Geequlim\t"            "Compile on "__DATE__<<endl;return true;}return false;}int main(int argc , char * argv[]){string command="adb connect ";string input;string ipAdress="192.168." ;if( argc>=2   ){if( argc>=3 )//more than 2 arguments{if (strcmp( argv[1] , "-d" ) ==0 )command = "adb disconnect ";//disconnect allif (strcmp( argv[2],"all")==0)ipAdress=" ";else //disconnect target input = argv[2];}else//1 or 2 arguments{//if the second argument is not --help or --version but -d or ip adressif(showInfo(argv[1])==false){if (strcmp( argv[1] , "-d" ) ==0 )//disconnet all devices{command = "adb disconnect ";ipAdress = " ";}elseinput = argv[1];}else return 0;}}else{cout<<"Input your phone ip adress :"<<flush;cin>>input;}if( argc>1 && strcmp(argv[1],"-d") && input.size() <3 ){cerr<<"Worr Input!"<<endl;return 1;}else if(  input.size()<8)ipAdress+=input;else if (  input.size()>15 || (input.size()< 11&&(input.size()>=8)) ){cerr<<"Worr Input!"<<endl;  return 1;}elseipAdress = input;cout<<command+ipAdress<<endl;system( (command+ipAdress).c_str() );system("adb devices");return 0;}

  

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.