Retrieving Application Name via ADB Shell

Retrieving Application Name via ADB Shell

30 November 2024 Stephan Petzl Leave a comment Tech-Help

When developing applications that interact with Android devices through ADB (Android Debug Bridge), you may find yourself needing to retrieve the application name or label using the package name. This guide will walk you through the most efficient methods to accomplish this task.

Method 1: Using ADB Shell and Dumpsys

The first approach involves using the adb shell pm list packages command to list all installed package names. Once you have the package name, you can extract more detailed information using:

adb shell dumpsys | grep -A18 "Package [my.package]"

This command will provide version identifiers and other package details, which can be useful but doesn’t directly give you the application name.

Method 2: Using AAPT Tool

A more direct method to retrieve the application name is by utilizing the AAPT (Android Asset Packaging Tool). This tool allows you to extract application labels directly from the APK file. Follow these steps:

  1. Identify the APK path using the package name:
    adb shell pm list packages -f com.example.myapp
  2. Use the AAPT tool to dump the badging information:
    adb shell aapt dump badging /path/to/apk

    Look for the line containing application-label: to find the app name.

Note: The AAPT tool is not included by default on all devices, so you might need to install it separately.

Method 3: Automating with Shell Script

If you frequently need to perform this task, consider using a shell script to automate the process. Here’s a basic example:

#!/bin/bash
for pkg in $(adb shell pm list packages -3 | cut -d':' -f2); do
    apk_loc="$(adb shell pm path $pkg | cut -d':' -f2)"
    apk_name="$(adb shell aapt dump badging $apk_loc | grep -oP "application-label:'\K[^']+")"
    echo "$pkg: $apk_name"
done
    

This script lists all user-installed packages and retrieves their application names.

Conclusion

Choosing the right method depends on your specific requirements and the tools available in your development environment. For those looking for a streamlined approach to testing Android applications, consider using Repeato, a no-code test automation tool. Repeato leverages computer vision and AI to automate testing processes, simplifying tasks such as executing ADB commands through its script steps feature. This integration can significantly enhance your testing efficiency, particularly when dealing with complex testing scenarios.

For further reading on ADB commands and Android testing, explore our Android Testing Tool documentation and our blog for more insights and updates.

Like this article? there’s more where that came from!