Android Question Read App Title from APK file!

aidymp

Well-Known Member
Licensed User
Longtime User
Hi, reading the info from an APK file - NOT an installed app!!!

Using this code i can see the packageName, versionName, versionCode?!? And in most cases the apps Icon, But I want the application title (The one shown by the launcher and in the title bar on most apps)

B4X:
Dim icon As BitmapDrawable
    Dim r, r2 As Reflector
    Dim packageName, fullpath As String
      
    File.Copy(File.DirAssets,"b4a_bridge.apk",File.DirInternal,"b4a_bridge.apk")
    fullpath = File.Combine(File.DirInternal, "b4a_bridge.apk")
  
    r.Target = r.GetContext
    r.Target = r.RunMethod("getPackageManager") ' PackageManager
    r2.Target = r.RunMethod3("getPackageArchiveInfo", fullpath , "java.lang.String", 1, "java.lang.int") ' List<PackageInfo>
  
  
    packageName=r2.GetField("packageName")
  
    Log(r2.GetField("packageName"))
    Log(r2.GetField("versionName"))
    Log(r2.GetField("versionCode"))
    'Log(r2.GetField("applicationLabel"))  Trying to get the - App Title?!

    r2.Target=r2.GetField("applicationInfo")
    r2.SetField("publicSourceDir",fullpath , "java.lang.String")
    r2.SetField("sourceDir",fullpath , "java.lang.String")
  
    Try
  
    icon=r.RunMethod4("getApplicationIcon",   Array As Object(r2.Target), Array As String("android.content.pm.ApplicationInfo"))
    Msgbox2(packageName, "packageIcon", "Close", "", "", icon.Bitmap)
  
    Catch
        Log("Error / No Image")
    End Try

How can I get the app title? and why is the icon hit and miss?

I have added a small project to play with! ;)

The first person to post the working code will be sent 10 euros via paypal!

Thanks!
 

Attachments

  • apkinfo.zip
    132.9 KB · Views: 142
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
File.Copy(File.DirAssets,"apkinfo.apk",File.DirInternal,"apkinfo.apk")
Dim fullpath As String = File.Combine(File.DirInternal, "apkinfo.apk")
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Dim PackageInfo As JavaObject = PackageManager.RunMethod("getPackageArchiveInfo", Array(fullpath, 0))
Dim ApplicationInfo As JavaObject = PackageInfo.GetField("applicationInfo")
ApplicationInfo.SetField("sourceDir", fullpath)
ApplicationInfo.SetField("publicSourceDir", fullpath)
Dim AppName As String = ApplicationInfo.RunMethod("loadLabel", Array(PackageManager))
Log(AppName)
Based on: https://stackoverflow.com/questions/38996063/application-info-of-a-non-installed-app
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
B4X:
File.Copy(File.DirAssets,"apkinfo.apk",File.DirInternal,"apkinfo.apk")
Dim fullpath As String = File.Combine(File.DirInternal, "apkinfo.apk")
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Dim PackageInfo As JavaObject = PackageManager.RunMethod("getPackageArchiveInfo", Array(fullpath, 0))
Dim ApplicationInfo As JavaObject = PackageInfo.GetField("applicationInfo")
ApplicationInfo.SetField("sourceDir", fullpath)
ApplicationInfo.SetField("publicSourceDir", fullpath)
Dim AppName As String = ApplicationInfo.RunMethod("loadLabel", Array(PackageManager))
Log(AppName)
Based on: https://stackoverflow.com/questions/38996063/application-info-of-a-non-installed-app

Thankyou Erel! it worked as expected!

As promised I will pay 10 euros to yourself or a nominated charity. PM me the details of where you would like the payment sent.

Aidy
 
Upvote 0
Top