Friday, May 2, 2014

Android Package Name From APK Code

Android apps are supplied in .apk files(even if you download from Play store) which contain all information needed to install an app to an Android smart phone.
Once an app is installed on a phone it is identified by a unique package name, the package name format is:

This value is taken from the Manifest.xml file which is already present inside the .apk file.
If we search "get package name from .apk" on Google we won't be able to find the source code to do this on the first page, almost everyone tries to tell us that this will be done through command line.

Package Archive files

There is a little twist behind these search results, is there another name for .apk files?
Yes sir, the full name of .apk files is "Package Archive". You can say that's the legal name .apk is only a nick name used by the Linux OS (Android is a Linux) and developer community.

It is possible to retrieve various nuggets of information Android package archive or .apk files using Android PackageManager class.
The will return the information about your package (or .apk) in a object.

Java Source Code
The Java language source code to get the package name from an .apk file is given below.

public String getPackageNameByAPK(String _strAPKPath, Context _activityORservice){
 String strRetVal = "";
 PackageManager packMan = null;
 PackageInfo packInfo = null;


  if(_strAPKPath == null) return "";

  Log.d(K.ATAG, "getPackageNameByAPK(): " + _strAPKPath);
  if(_activityORservice == null) {
   Log.e(K.ATAG, "Context is null");
    return "";   

 packMan = _activityORservice.getPackageManager();  
 packInfo = packMan.getPackageArchiveInfo(_strAPKPath, 0);
 strRetVal = packInfo.packageName;
 }catch(Exception e){
  Log.e(K.ATAG, e.toString() + "" );

  Log.d(K.ATAG, "RetVal: " + strRetVal);
 return strRetVal;
}//Beautify code with

Note, this is actually WORKING CODE, copied straight from one of my already deployed apps.
All you need is some common sense and a mug of coffee before performing the magical copy/paste operation.

An instance of the Package Manager can be acquired by calling getPackageManager() method of android.content.Context class, which actually represents the activity or service from which you are making the method call.

The details about PackageManager and the method getPackageArchiveInfo can be found on the URL given below:

I'm working as a freelance programmer through, my profile clearly reflects what I am made of. Feel free to ping me if you need an Android app for yourself or your employer.

I'm working as a freelance programmer through, I have a strong profile over there. Feel free to ping me if you need an Android app.


  1. Did you ever think is it possible to edit an APK file or change the way it works?

  2. Abdul Sattar, yes it is possible to "unpack" an APK and extract its code, modify it and re-package it again.

    Check this link:

    The changes are done in smali language which is really complicated, it is made so on purpose to make reverse engineering difficult. I tried to do it on behalf of a freelance client once, but we didn't make much progress so the project was ended after a week or so.

  3. Hy author,
    I am founder of game killer
    I like your article THANKS FOR SHARING


Feel free to talk back...