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

后端 未结 4 1276
失恋的感觉
失恋的感觉 2020-12-10 16:37

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 ?

Th

4条回答
  •  Happy的楠姐
    2020-12-10 17:17

    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

提交回复
热议问题