I have a simple android app .apk file create with Expo (react native) using the expo build:android script.
I am trying to run this on a device which is locked down by the provider so their is no access to Expo client. The only interface is via ADB.
I have successfully installed the app using the following command:
adb -s <device_id> install <package-name>.apk
I am then trying to start the app via the following:
adb shell am start -n host.exp.myapp
But I get the following error:
Exception: java.lang.IllegalArgumentException: Bad component name: host.exp.myapp
When I run adb shell cmd package list packages, I can see the package:host.exp.myapp listed and I am sure it's following naming conventions with lowercase and no special characters.
How can I start my app via ADB?
Use the command adb shell monkey -p com.package.name -c android.intent.category.LAUNCHER 1
It starts the activity as if it was launched using the launcher. Replace com.package.name with desired package name in the command.
If you only know the package name and not the Activity you can use AndroidViewClient/culebra which resolves it.
For example, if you only knows the Chrome package name com.android.chrome you can run
#! /usr/bin/env python3
from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(package='com.android.chrome')
and it is resolved to the main Activity and then started.
If you want to do it from adb without using python you can take a look at the source here.
I have to call an Android app from my application. But I don't know package name of the application, I want to call that application via package name by using adb command
Using ADB if the app is already installed
If the app is already installed on your Fire TV or other Android device, you can run a shell command that lists all the apps, with their package names, that are installed on your device. First, connect to your device via ADB, then run the command adb shell pm list packages -3 -f. That will list all the apps you’ve personally installed on the device. If you want to see a list of all the apps, including system apps, then run the command adb shell pm list packages -f instead. Each line of the app list that is displayed will end in the app’s package name. For example, package:/data/app/org.xbmc.kodi-1/base.apk=org.xbmc.kodi is the line for Kodi. The package name should be descriptive enough for you to be able to pick out the app you’re looking for. thanks for Elias Saba see this tutorial for more clarity
adb shell pm list packages -f
Lists all installed packages
You can use grep to find specific package
adb shell pm list packages -f | grep com.android.bluetooth
I've to install an android app with package name like "com.xyz.game" using adb.
I want to automate the process using shell script. The process will be like if app is already installed, uninstall it(with command adb uninstall com.xyz.game) and install using "adb install game.apk" otherwise simple "adb install game.apk".
How can I achieve this?
[Update 2]
Without using grep
adb shell pm list packages [your.package.name] as mentioned in the below answer
[Update]
According to (also) correct answer below, try grep the result from pm list packages.
adb shell pm list packages | grep com.your.app.package
[Original]
If the application is already installed and if you try to install the same app again, adb will return with an error - Failure [INSTALL_FAILED_ALREADY_EXISTS]. However, if you want to re-install the already installed app, then use -r parameter.
Ex:
adb install -r game.apk
Try grep the result from pm list packages.
adb shell pm list packages | grep com.xyz.game
You may see the result if already installed.
package:com.xyz.game
No need to use grep. Using following commands you can simply check if application is already exist or not.
Run ADB command
adb shell pm list packages [your.package.name]
If app is already installed then above command will return,
package:[your.package.name]
Else it won't return anything i.e. empty String.
Android 7.0 has introduced cmd (a new native code based) tool which allows to interact with Android services like PackageManager much faster than the old java bytecode based tools like pm. So for recent Android versions instead of adb shell pm list packages <package.name.substring> you should use
adb shell cmd package list packages <package.name.substring>
Taking into account #Joel answer, just do it in one-liner
# uninstall only if exists
adb shell pm list packages | grep com.your.app.package && adb uninstall com.your.app.package
Use First adb shell command if you are using adb otherwise you can use use root in same device by su command
Then, we can get path of installed apk files by their pkg names lets say in our case pkg name is com.tencent.ig
pm path com.tencent.ig | sed 's/package://'
If app installed : You will get the path to the apk file
If app not installed : You will get nothing
Previous answers are limited but by using above logic we can also use if statement easily like :
pkg=com.tencent.ig #Add pkg of your app only here
if [ -f $(pm path $pkg | sed 's/package://') ]
then
echo "YES, app is installed"
#further commands if app is installed
else
echo "NO, app is not installed"
#further commands if app not installed
fi
I think that will be much handy.
This works fine :
adb shell pm list packages your.package.name
Replace your.package.name with the required package name.
If app installed : You will get the path to the apk file
If app not installed : You will get nothing
I've been trying to install Vending.apk into my emulator w/o success. It says it already exists and fails to replace it when I use adb install -r. The icon does not show up on the screen so I can't tap it to launch the Google Play marketplace.
Therefore, I thought I could run it from my PC (MacOSX) using adb like this:
adb shell am start -a android.intent.action.MAIN -n com.android.vending/.Vending
I constructed the above from examples that work in this article:
How to run (not only install) an android application using .apk file?
And I unzipped the AndroidManifest.xml file using info from this method to see if I could discover the activity name, but no luck:
aapt dump xmltree <apk-file> AndroidManifest.xml
I guess I need to know the exact command to execute the vending apk because I can't seem to find the correct Activity class. adb shell am start keeps giving me error type 3, Activity class does not exist.
Thanks
You can try this:
adb shell am start -n com.android.vending/com.google.android.finsky.activities.MainActivity
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.