How to run (not only install) an android application using .apk file?

前端 未结 7 1385
孤独总比滥情好
孤独总比滥情好 2020-11-29 18:04

Is there any command on cmd.exe that would allow me to start the main activity of a particular android application using the .apk file of that appl

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 18:45

    You can't install and run in one go - but you can certainly use adb to start your already installed application. Use adb shell am start to fire an intent - you will need to use the correct intent for your application though. A couple of examples:

    adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings 
    

    will launch Settings, and

    adb shell am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity 
    

    will launch the Browser. If you want to point the Browser at a particular page, do this

    adb shell am start -a android.intent.action.VIEW -n com.android.browser/.BrowserActivity http://www.google.co.uk
    

    If you don't know the name of the activities in the APK, then do this

    aapt d xmltree  AndroidManifest.xml
    

    the output content will includes a section like this:

       E: activity (line=32)
        A: android:theme(0x01010000)=@0x7f080000
        A: android:label(0x01010001)=@0x7f070000
        A: android:name(0x01010003)="com.anonymous.MainWindow"
        A: android:launchMode(0x0101001d)=(type 0x10)0x3
        A: android:screenOrientation(0x0101001e)=(type 0x10)0x1
        A: android:configChanges(0x0101001f)=(type 0x11)0x80
        E: intent-filter (line=33)
          E: action (line=34)
            A: android:name(0x01010003)="android.intent.action.MAIN"
            XE: (line=34)
    

    That tells you the name of the main activity (MainWindow), and you can now run

    adb shell am start -a android.intent.action.MAIN -n com.anonymous/.MainWindow
    

提交回复
热议问题