Android Question Display Package Name Label Name Apk Name for the same App

Mahares

Expert
Licensed User
Longtime User
I use the below code to display the package name and the label name, but I would like to also show the corresponding apk file name. Is there an easy way to extract it or perhaps use javaobject or reflection?

B4X:
Dim pm As PackageManager  'need phone library
For Each package As String In pm.GetInstalledPackages
        If  package.Contains("div")Then
            Log(pm.GetApplicationLabel(package))
            Log(package)
            Log("apk file name:")   'Need to extract the corresponding apk file name here
            Log("-----------")
        End If
   Next
Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim jpm As JavaObject = ctxt.RunMethod("getPackageManager", Null)
Dim pm As PackageManager
For Each pck As String In pm.GetInstalledPackages
   Dim ApplicationInfo As JavaObject = jpm.RunMethod("getApplicationInfo", Array(pck, 0))
   Log($"Package: ${pck}, Path: ${ApplicationInfo.GetField("publicSourceDir")}"$)
Next
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tried the above code as written by @Erel's , but unfortunately, the path for the non system apps always shows the same apk file name.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I attached a small project that demonstrates the behavior where the apk file name repeats itself for several of the packages installed on the device. Perhaps, some of the members can also test this tiny project and see if they can tweak it to get it to work properly or confirm that it is not doable.
Thank you
 

Attachments

  • PackageNameLabelApkFileName.zip
    8.3 KB · Views: 292
Upvote 0

Geezer

Active Member
Licensed User
Longtime User
It shows the packages correctly on my S8+, maybe it's your device ?

And as a side note, NONE of my packaages include DIV, not even the system apps.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It shows the packages correctly on my S8+, maybe it's your device ?
Thanks @Geezer for testing. I have tested it in 2 devices. One with OS 6.0.1 and one with 8.1 and I still have the same problem. Stroll down the logs, you will see in many packages the same apk name is shown for non system apps.
As far as the div, it is designed for me to display certain particular packages that have the word div in them. That is why I commented that line in the exported project.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Ok. That is what I found too. all apk are: base.apk. I am still at a loss why there is no solution to this. There is a good reason why I wanted this feature.
 
Upvote 0
Top