Search code examples
androidadb

Single adb shell command to find the current apk location and version


Using the following 3 commands, Can we have single adb shell command to know the current apk file location and version of the apk.

  1. we can use following command to find the all packages and locations of the apks

    adb shell pm list packages -f

  2. we can use following command to know the current package name.

    adb shell dumpsys window | grep -i mCurrentFocus

  3. we can use following command to know apk version

    adb shell dumpsys package my.package | grep versionName

This will be use full for every one to quickly check the current apk details immediately.

Example: If i open com.src.test application from device. i want to know where this apk installed (/system/app/) and version of apk (1.0101) using single adb shell command.


Solution

  • Something like this maybe?

    package=$(dumpsys window windows | grep mCurrentFocus | cut -d'/' -f1 | rev | cut -d' ' -f1 | rev) && dumpsys package $package | grep -E "versionName|codePath"
    

    codePath=/data/app/com.src.test

    versionName=1.0101