Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to get the name of apk file programmatically?

Tags:

file

android

apk

For some reasons, my app can be installed with different apk names. At launch, I would like to know what is the name of the apk file. Do you know how to do that ?

Thanks !

like image 573
Regis_AG Avatar asked Sep 30 '11 09:09

Regis_AG


People also ask

How do I find the package name of an APK?

You can find an app's package name in the URL of your app's Google Play Store listing. For example, the URL of an app page is play.google.com/store/apps/details? id=com. example.

Is there a way to get the source code from an APK file?

Simplest way: use the online tool Decompiler, upload the apk and get the source code.

What is APK name?

The full form of APK is an Android Application Package. APK is the application file type used in the Android operating system, as well as a wide range in many other Android-based operating applications in mobile phones, video games & middleware for distribution and installation.


1 Answers

final PackageManager pm = getPackageManager();
String apkName = "example.apk";
String fullPath = Environment.getExternalStorageDirectory() + "/" + apkName;        
PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0);

you can got it with:

info.versionCod

and

info.versionName

hope this help you

like image 74
mehrdad khosravi Avatar answered Oct 12 '22 23:10

mehrdad khosravi