1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

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

Discussion in 'Android Questions' started by Mahares, May 11, 2019.

  1. Mahares

    Mahares Well Known Member Licensed 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?

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    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
     
    Mahares likes this.
  3. Mahares

    Mahares Well Known Member Licensed 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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that there is any other way to get the APK name.
     
  5. Mahares

    Mahares Well Known Member Licensed 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
     

    Attached Files:

  6. Geezer

    Geezer Active Member Licensed 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.
     
  7. Mahares

    Mahares Well Known Member Licensed User

    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.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    There is no special reason for the OS to keep the original APK name. The APK name has no meaning.

    On my Android 9 device all the APK names end with base.apk.
     
  9. Mahares

    Mahares Well Known Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice