3

I know how to install and run apk through cmd with this command:

adb install SimpleClientActivity.apk

and:

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

How can I run this command on all connected devices?

CL.
  • 173,858
  • 17
  • 217
  • 259
Hussnain Azam
  • 358
  • 1
  • 5
  • 14
  • possible duplicate of [How can I adb install an apk to multiple connected devices?](http://stackoverflow.com/questions/8610733/how-can-i-adb-install-an-apk-to-multiple-connected-devices) – Adinia Mar 14 '14 at 09:59

2 Answers2

1

Here and here you have an answer.

You can also build you projects with Maven and after clean install, type: mvn android:deploy android:run.

Community
  • 1
  • 1
mmBs
  • 8,421
  • 6
  • 38
  • 46
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.

Fabian W
  • 54
  • 6
  • How does this work on windows? Did you install anything(eg Cygwin)? On my Win7 machine this script fails in the first line. Even if I remove the first part tail cannot be found. – simonides Jan 06 '15 at 18:42
  • This is not a Windows Batch script. This is a Linux Bash script. (Will not work on Windows as is) – BayssMekanique Feb 16 '15 at 22:37