我知道如何使用此命令通过cmd安装和运行apk:
adb install SimpleClientActivity.apk
和
adb shell am start -n com.example.simpleclientactivity/.SimpleClientActivity
如何在所有连接的设备上运行此命令?
答案 0 :(得分:1)
答案 1 :(得分:0)
要为多个设备安装并自动启动应用程序,最简单的方法是在我看来使用命令行和Windows Batch脚本:
<!-- 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,但我对Batch文件知之甚少,但它只是运行。 ;)
<!-- 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 即可在所有设备上启动该应用。