我知道如何使用以下命令通过cmd安装和运行apk:
adb install SimpleClientActivity.apk和:
adb shell am start -n com.example.simpleclientactivity/.SimpleClientActivity如何在所有连接的设备上运行此命令?
发布于 2013-08-05 15:59:14
发布于 2014-04-19 09:48:30
要为多个设备安装并自动启动应用程序,最简单的方法是使用命令行和Windows批处理脚本。
<!-- language: Batch script -->
:: This five lines are used to minimize the
:: command lines directly after the start
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
:: Path to the ADB and to the APK file
@set ADB="D:/Android/sdk/platform-tools/adb.exe"
@set APK="D:/workspace_android/SomeApp/bin/SomeApp.apk"
:: AndroidManifest.xml: <manifest package="com.example.appname">
:: The launching activity: <activity android:name=".activities.HomeActivity">
@set ACTIVITY=at.example.appname/.activities.HomeActivity
:: Install APK on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: Launch App on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%在我的例子中,我有三个设备。为了更快地访问一个设备,我使用了下面的代码,而不是上面代码中的循环。首先,我在速度最快的设备上安装和启动应用程序,然后在第二个设备上安装和启动应用程序,依此类推。我相信有更好的方法来代替使用tail、head和xargs,但我对批处理文件了解不多,但它只是运行。;)
<!-- language: Batch script -->
:: NEXUS 5
:: This command reinstalls the APK on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: This command launch the application on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
:: Galaxy Tab
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
:: Optimus 3D
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%拥有Windows批处理脚本后,创建该文件的快捷方式。右键单击快捷方式文件,然后选择属性。您可以在其中指定全局快捷键,例如STRG+ALT+F10。
只需按下STRG+ALT+F10,该应用程序就会在所有设备上启动。
https://stackoverflow.com/questions/18052953
复制相似问题