Android: launch app info dialog via adb shell am - android

I'm trying to write a script which will launch the "app info" system dialog via adb for an app I'm testing.
I have done some investigation and came up with this command, which will launch "app info" but fails with a force close (NullPointerException in logcat):
adb shell am start -a android.intent.action.VIEW -n com.android.settings/.applications.InstalledAppDetails -es com.android.settings.ApplicationPkgName com.my.app -es pkg com.my.app
Seems that the package name isn't being properly passed.
What is the correct way to pass the package name parameter to the am command in this case?

adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:<package-name>

Also, check this: https://stackoverflow.com/a/4567928/4409113
adb shell am start -n com.package.name/com.package.name.ActivityName
http://developer.android.com/tools/help/shell.html#am
You can also issue an activity manager command directly from adb
without entering a remote shell.
For example:
adb shell am start -a android.intent.action.VIEW
Seems like, start -a is a good way.

Related

Can I use adb to call the "package installer" to install the application? adb install is not allowed

I tried to use the following code, but reported to me "shell does not declare android.permission.REQUEST_INSTALL_PACKAGES"
adb shell am start -a android.intent.action.VIEW -t "application/vnd.android.package-archive" -d "file:///sdcard/Download/a.apk"
I am sad that for some reasons, adb install is not allowed, even if I run the following command, I still cannot install the application
adb shell settings put global verifier_verify_adb_installs 0
adb shell settings put global package_verifier_enable 0
logļ¼šFailure [INSTALL_FAILED_VERIFICATION_FAILURE: adb install not allowed!]

ADB to Launch android browser with given url

I am trying to send a commend via ADB to launch different browsers with a given URL.
I only know the package names of the browsers so I used:
adb shell monkey -p com.android.chrome -c android.intent.category.LAUNCHER 1
This way I could open the app with only the package name, but I couldn't pass any URL to it.
I could pass a URL to chrome using:
adb shell am start -a android.intent.action.VIEW -d https://www.bbc.com/
but this requires more then just package name.
Trying to combine these two didn't work:
adb shell monkey -p com.android.chrome -c android.intent.category.LAUNCHER 1 -d https://www.yahoo.com
What is the correct way to pass a URL to a browser using only the package name with monkey?
Thank you all!
adb shell am start -a android.intent.action.VIEW -d http://www.facebook.com

adb "am start -n" not working for debug version

I am trying to use adb to launch activites for testing,But it does not work for the debug version :
This works
adb shell am start -n com.xx.xx/.main.ParentActivity
This doesn't
adb shell am start -n com.xx.xx.debug/.main.ParentActivity
Both debug and release packages are available under /data/data
If you have class com.xx.xx.main.ParentActivity and your application id is com.xx.xx.debug then you have to specify FQCN like this:
adb shell am start -n com.xx.xx.debug/com.xx.xx.main.ParentActivity
Dot just after slash is shortcut which can be used only if FQCN starts with application id.
use adb shell am start -D -n com.xx.xx.debug/.main.ParentActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
then you will be able to attach your debugger (via your IDE) and the app will start (see https://blog.jetbrains.com/idea/2011/05/new-in-105-attach-debugger-to-a-running-android-process/)

How to launch android gallery app using adb shell?

I tried a lot and got
adb shell am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity
for launching browser so I tried the same with gallery and I'm stuck with this
adb shell am start -a android.intent.action.MAIN -n com.sec.android.gallery3d/.GalleryActivity</b><br/>
I know GalleryActivity is not available but what else can i use?
Note: I am using samsung Galaxy S3 mini so the package name is com.sec.android.gallery3d
We can use monkey to open any app through adb shell,
Try the below command,
$ adb shell monkey -p com.android.gallery3d 1
In my nexus4, Gallery app package name is com.android.gallery3d and we are just passing 1 event via monkey, So that monkey will just open the app and will not do anything further.
Also this approach helps you to open any app just with the package name. Monkey will pick the launcher activity by itself.
Hope it helps.
maybe
adb shell am start -t image/* -a android.intent.action.VIEW
also one more thing , this will open the default app selected for gallery in your device.

How to start an application using Android ADB tools

How do I send an intent using Android's ADB tools?
adb shell
am start -n com.package.name/com.package.name.ActivityName
Or you can use this directly:
adb shell am start -n com.package.name/com.package.name.ActivityName
You can also specify actions to be filter by your intent-filters:
am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName
It's possible to run an application specifying the package name only using the monkey tool by follow this pattern:
adb shell monkey -p your.app.package.name -c android.intent.category.LAUNCHER 1
The command is used to run the app using the monkey tool which generates random input for the application. The last part of the command is an integer which specifies the number of generated random input for the app. In this case the number is 1, which in fact is used to launch the app (icon click).
Or, you could use this:
adb shell am start -n com.package.name/.ActivityName
Linux and Mac users can also create a script to run an APK file with something like the following:
Create a file named "adb-run.sh" with these three 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 Android Asset Packaging Tool (aapt) in your path. You can find it under the new build tools folder in the SDK.
Step 1: First get all the package names of the apps installed in your device, by using:
adb shell pm list packages
Step 2: You will get all the package names. Copy the one you want to start using ADB.
Step 3: Add your desired package name in the below command.
adb shell monkey -p 'your package name' -v 500
For example,
adb shell monkey -p com.estrongs.android.pop -v 500
to start the Es explorer.
The shortest command yet is the following:
adb shell monkey -p your.app.package.name 1
This will launch the default activity for the package that is in the launcher.
Thanks to Androiderson for the tip.
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 a Play Store activity from adb shell am, pressing the 'Back' button (hardware back button) wouldn't take you back to your app. Instead, it would take you to the previous Play Store activity if there was some (if there was not a Play store task, then it would take you back to 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.
We can as well start an application by knowing the application type and feeding it with data:
adb shell am start -d "file:///sdcard/sample.3gp" -t "video/3gp" -a android.intent.action.VIEW
This command displays available *video players to play a sample.3gp file.
You can find your app package name by the below command:
adb shell pm list packages
The above command returns a package list of all apps. Example:
org.linphone.debug
.
.
com.android.email
Now I want to start app linphone by using the below command and this worked for me:
adb shell am start org.linphone.debug
Open file ~/.bash_profile, and add these Bash functions to the end of the file
function androidinstall(){
adb install -r ./bin/$1.apk
}
function androidrun(){
ant clean debug
adb shell am start -n $1/$1.$2
}
Then open the Android project folder:
androidinstall app-debug && androidrun com.example.app MainActivity
monkey --pct-syskeys 0 for development boards
This argument is needed for development boards without keys/display:
adb shell monkey --pct-syskeys 0 -p com.cirosantilli.android_cheat.textviewbold 1
Without it, the app won't open, and you will get an error message like:
SYS_KEYS has no physical keys but with factor 2.0%
It was tested on HiKey960, Android O AOSP.
Learned from: this GitHub issue
Also asked at: How to use the monkey command with an Android system that doesn't have physical keys?
Use:
adb shell am start -n '<appPackageName>/.<appActitivityName>
Example:
adb shell am start -n 'com.android.settings/.wifi.WifiStatusTest'
You can use the APK-INFO application to know the list of app activities with respect to each app package.
adb shell am start -n com.app.package.name/com.java.package.name.ActivityName
Example
adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.search.core.google.GoogleSearch
If the Java package is the same, then it can be shortened:
adb shell am start -n com.example.package/.subpackage.ActivityName
Use:
adb shell am start -n '<appPackageName>/<appActitivityName>'
To get <appPackageName> run :
adb shell pm list packages
To get <appActitivityName> lunch app and run
adb shell dumpsys window | grep -E 'mCurrentFocus'
Try this, for opening an Android photo app and with the specific image file to open as a 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 version of Android. No pop up will come to select an application to open as you are giving the specific app to which you want to open your image with.
When you try to open a Flutter app, you can use this command:
adb shell am start -n com.package.name/io.flutter.embedding.android.FlutterActivity
Replace com.package.name with your package name. You find your package in your app/build.gradle at applicationId.

Categories

Resources