Get Application Name/ Label via ADB Shell or Terminal

后端 未结 5 838
南旧
南旧 2020-12-12 14:13

I\'m developing an application that uses ADB Shell to interface with android devices, and I need some way of printing out the application name or label of an application, gi

相关标签:
5条回答
  • 2020-12-12 14:58

    just enter the following command on command prompt after launching the app:

    adb shell dumpsys window windows | find "mCurrentFocus"
    

    if executing the command on linux terminal replace find by grep

    0 讨论(0)
  • 2020-12-12 15:02

    A shell script to accomplish this:

    #!/bin/bash
    
    # Remove whitespace
    function remWS {
        if [ -z "${1}" ]; then
            cat | tr -d '[:space:]'
        else
            echo "${1}" | tr -d '[:space:]'
        fi
    }
    
    for pkg in $(adb shell pm list packages -3 | cut -d':' -f2); do
        apk_loc="$(adb shell pm path $(remWS $pkg) | cut -d':' -f2 | remWS)"
        apk_name="$(adb shell aapt dump badging $apk_loc | pcregrep -o1 $'application-label:\'(.+)\'' | remWS)"
        apk_info="$(adb shell aapt dump badging $apk_loc | pcregrep -o1 '\b(package: .+)')"
    
        echo "$apk_name v$(echo $apk_info | pcregrep -io1 -e $'\\bversionName=\'(.+?)\'')"
    done
    
    0 讨论(0)
  • 2020-12-12 15:03

    adb shell pm list packages will give you a list of all installed package names.

    You can then use dumpsys | grep -A18 "Package \[my.package\]" to grab the package information such as version identifiers etc

    0 讨论(0)
  • 2020-12-12 15:05

    Inorder to find an app's name (application label), you need to do the following:
    (as shown in other answers)

    1. Find the APK path of the app whose name you want to find.
    2. Using aapt command, find the app label.

    But devices don't ship with the aapt binary out-of-the-box.
    So you will need to install it first. You can download it from here:
    https://github.com/Calsign/APDE/tree/master/APDE/src/main/assets/aapt-binaries


    Check this guide for complete steps:
    How to find an app name using package name through ADB Android?
    (Disclaimer: I am the author of that blog post)

    0 讨论(0)
  • 2020-12-12 15:08

    If you know the app id of the package (like org.mozilla.firefox), it is easy. First to get the path of actual package file of the appId,

    $  adb shell pm list packages -f com.google.android.apps.inbox
    package:/data/app/com.google.android.apps.inbox-1/base.apk=com.google.android.apps.inbox
    

    Now you can do some grep|sed magic to extract the path : /data/app/com.google.android.apps.inbox-1/base.apk

    After that aapt tool comes in handy :

    $  adb shell aapt dump badging /data/app/com.google.android.apps.inbox-1/base.apk
    ...
    application-label:'Inbox'
    application-label-hi:'Inbox'
    application-label-ru:'Inbox'
    ...
    

    Again some grep magic to get the Label.

    0 讨论(0)
提交回复
热议问题