Automatically launch Android application after downloading it to your phone?

During the development of Android applications, I often do the following:

  • Run "ant reinstall" to compile and load the application into the emulator.
  • Switch to the emulator window.
  • Click on the package I just downloaded to test it.

Is there any way to tell the emulator phone to run the package I just downloaded? Maybe the adb command that I can send after running my script compiler? As a last resort, I think I could run something that mimics a mouse click for me.

+5
source share
1 answer

am. , , :

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.MyApp">
    <application android:icon="@drawable/icon">
        <activity class=".MyMainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:value="android.intent.action.MAIN" />
                <category android:value="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    ...
</manifest>

:

adb shell am start -a android.intent.action.MAIN -n com.example.MyApp/.MyMainActivity

, :

adb wait-for-device shell am start -a android.intent.action.MAIN -n com.example.MyApp/.MyMainActivity

Intent, Activity.

( am --help):

usage: am [start|broadcast|instrument|profile]
       am start [-D] INTENT
       am broadcast INTENT
       am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]
                [-w] <COMPONENT> 
       am profile <PROCESS> [start <PROF_FILE>|stop]

       INTENT is described with:
                [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
                [-c <CATEGORY> [-c <CATEGORY>] ...]
                [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
                [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
                [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
                [-n <COMPONENT>] [-f <FLAGS>] [<URI>]
+3

All Articles