How to start an application using android ADB tools?

后端 未结 11 1078
醉酒成梦
醉酒成梦 2020-11-22 07:23

How do I send an intent using Android\'s ADB tools?

相关标签:
11条回答
  • 2020-11-22 07:57

    Also, I want to mention one more thing.

    When you start an application from adb shell am, it automatically adds FLAG_ACTIVITY_NEW_TASK flag which makes behavior change. See the code.

    For example, if you launch Play Store activity from adb shell am, pressing 'Back' button(hardware back button) wouldn't take you your app, instead it would take you previous Play Store activity if there was some(If there was not Play store task, then it would take you your app). FLAG_ACTIVITY_NEW_TASK documentation says :

    if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in

    This caused me to spend a few hours to find out what went wrong.

    So, keep in mind that adb shell am add FLAG_ACTIVITY_NEW_TASK flag.

    0 讨论(0)
  • 2020-11-22 07:59

    Try this, for opening an android photo app & with specific image file to open as parameter.

    adb shell am start -n com.google.android.apps.photos/.home.HomeActivity -d file:///mnt/user/0/primary/Pictures/Screenshots/Screenshot.png

    It will work on latest android, no pop up will come to select an application to open as you are giving specific app to which you want to open your image with

    0 讨论(0)
  • 2020-11-22 08:01

    linux/mac users can also create a script to run an apk with something like the following:

    create a file named "adb-run.sh" with these 3 lines:

    pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
    act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
    adb shell am start -n $pkg/$act
    

    then "chmod +x adb-run.sh" to make it executable.

    now you can simply:

    adb-run.sh myapp.apk

    The benefit here is that you don't need to know the package name or launchable activity name. Similarly, you can create "adb-uninstall.sh myapp.apk"

    Note: This requires that you have aapt in your path. You can find it under the new build tools folder in the SDK.

    0 讨论(0)
  • 2020-11-22 08:03
    adb shell am start -n '<appPackageName>/.<appActitivityName>
    

    Ex:

    adb shell am start -n 'com.android.settings/.wifi.WifiStatusTest'
    

    You can use APK-INFO application to know the list of App Activities with respect to each App Package

    0 讨论(0)
  • 2020-11-22 08:10

    Or, you could use this:

    adb shell am start -n com.package.name/.ActivityName
    
    0 讨论(0)
提交回复
热议问题