shell – Android: How to Know if any application is already installed in android device using adb?-ThrowExceptions

Exception or error:

I’ve to install an android app with package name like “” 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 and install using “adb install game.apk” otherwise simple “adb install game.apk”.

How can I achieve this?

How to solve:

[Update 2]

Without using grep

adb shell pm list packages [] as mentioned in the below answer


According to (also) correct answer below, try grep the result from pm list packages.

adb shell pm list packages | grep


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.


adb install -r game.apk


Try grep the result from pm list packages.

adb shell pm list packages | grep

You may see the result if already installed.


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 []

If app is already installed then above command will return,


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 <> you should use

adb shell cmd package list packages <>

Leave a Reply

Your email address will not be published. Required fields are marked *