3

我知道如何使用以下命令通过 cmd 安装和运行 apk:

adb install SimpleClientActivity.apk

和:

adb shell am start -n com.example.simpleclientactivity/.SimpleClientActivity

如何在所有连接的设备上运行此命令?

4

2 回答 2

1

在这里这里你有一个答案。

您还可以使用 Maven 构建您的项目,并在全新安装后键入:mvn android:deploy android:run

于 2013-08-05T07:59:13.600 回答
0

To install and automatically launch the app for multiple devices, the easiest way is to use the command line and a Windows Batch script in my opinion:

<!-- 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%

In my case I have three devices. For faster access to one device, I used the following code instead of the loop in upper code. First, I install and launch the app on the fastest device and after that on the second and so on. I am sure there are better ways instead of using tail, head and xargs, but I don't know that much about Batch files, but it just runs. ;)

<!-- 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%

After having the Windows Batch script, create a shortcut of that file. Right click the shortcut file and select properties. There you can specify a global shortcut key for example STRG+ALT+F10.

Just press STRG+ALT+F10 and the app will be launched on all devices.

于 2014-04-19T01:48:30.263 回答