1

I am writing a command line tool to get app name by package name, and trying the following ways.

  1. PackageManager in android API provide the function, but mine tool is not an APK, thus there's no Context.

  2. command AAPT can parse app name from apk, adb shell aapt dump badging /data/app/com.google.android.apps.inbox-1/base.apk, but my device has no aapt, I downloaded one from here, it complains "error: only position independent executables (PIE) are supported".

any helps?

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
Cosmore
  • 3,193
  • 4
  • 20
  • 22

2 Answers2

1

To get App Name try this. It would provide the application name which is defined in tag of app's manifest.

PackageManager packageManager = getApplicationContext().getPackageManager();
    ApplicationInfo applicationInfo ;
    try {
        applicationInfo = packageManager.getApplicationInfo( this.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        applicationInfo = null;
    }
    String applicationName = (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo ) : "(unknown)");
Deepak Sachdeva
  • 950
  • 8
  • 16
  • He cannot do that. He doesn't want to get app name in his android app. He is developing a cmd tool which can retrieve the name of app from package. He mentioned that in his question. – Dhrumil Patel Dec 09 '16 at 06:58
0

You can use AAPT2 command in linux to get the package name of an APK.

./aapt2 dump packagename <path_to_apk>

But you need to download newer versions of AAPT2 from here: Download AAPT from Google Maven

You can try this executing this command in a shell script, so that you will be able to use the package name.

PS: I used AAPT2 version 3.3.0-5013011 for testing the above command.

user198530
  • 331
  • 1
  • 3
  • 10