Retrieving Application Names Using ADB Shell

Retrieving Application Names Using ADB Shell

22 April 2024 Stephan Petzl Leave a comment Tech-Help

Android developers and testers often need to interact with devices at a level deeper than the user interface. One such interaction involves retrieving application names, a task that can be accomplished through the Android Debug Bridge (ADB) shell. This guide will walk you through the process of obtaining application names from package names using ADB commands.

Prerequisites

  • ADB installed on your computer
  • Developer options and USB debugging enabled on your Android device
  • A connection established between your Android device and computer

Step-by-Step Process

  1. List Installed Packages:

    Start by listing all installed packages on the device with the following command:

    adb shell pm list packages

    This command will output a list of installed packages by their package names.

  2. Retrieve Package Information:

    Once you have the package name, you can obtain detailed information about the package using:

    adb shell dumpsys package my.package.name

    Replace my.package.name with the actual package name. This command provides extensive details about the package, including its version.

  3. Extracting the Application Label:

    For a more direct approach to obtaining just the application label, the aapt tool can be used in conjunction with the package’s APK path:

    adb shell aapt dump badging /path/to/apk | grep "application-label:"

    This will display the application label for the specified APK.

    Note that the aapt tool might not be available on all devices by default. You may need to install it or use an alternative method to obtain the APK path.

Automating the Process

For those who require automation or frequently perform this task, scripting can be a powerful way to streamline the process. Below is an example of a bash script that combines the above steps to match package names to application labels:

#!/bin/bash
for pkg in $(adb shell pm list packages -3 | cut -d':' -f2); do
    apk_path=$(adb shell pm path $pkg | cut -d':' -f2)
    app_label=$(adb shell aapt dump badging $apk_path | grep "application-label:" | cut -d"'" -f2)
    echo "$pkg: $app_label"
done

This script lists third-party packages, extracts their APK paths, retrieves their application labels, and then outputs them in a readable format.

Introducing “Repeato”

While the above method works well for obtaining application names, it’s just one piece of the puzzle in the broader scope of app testing. This is where Repeato comes into play. Repeato is a no-code test automation tool that not only eases the process of creating, running, and maintaining automated tests for iOS and Android apps but also supports all sorts of app-frameworks.

With its built-in ADB capabilities, Repeato allows you to execute ADB commands via script steps, offering a seamless integration with your existing testing workflows. Its use of computer vision and AI for test creation and execution makes it a robust solution for ensuring your app’s quality without the steep learning curve often associated with automation tools.

In conclusion, whether you’re retrieving application names or conducting comprehensive UI tests, integrating tools like ADB and Repeato can significantly enhance your productivity and app quality.

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