List of all apps installed by the user?

Kiffi

Well-Known Member
Licensed User
Longtime User
Hello,

with the following snippet i am able to get a list of all packages on my phone:

B4X:
Dim pm As PackageManager
Dim packages As List
packages = pm.GetInstalledPackages
For i = 0 To packages.Size - 1
    Log(packages.Get(i))
Next

But how to get a list of all packages installed by the user? (all Apps i am able to uninstall)

Thanks & Greetings ... Kiffi
 

wes58

Active Member
Licensed User
Longtime User
I have been using similar code to get the list of applications and application icons and it worked ok, until I upgraded the phone to Lollipop.
Now I get an error on line Dim bdw As BitmapDrawable = pm.GetApplicationIcon(p): "java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable" . When the error is dismissed, it still displays the icon in the listview OK OK.

First: LOL... Tried the forumsearch? :D

You dont need reflector for this. Just add Phone library
B4X:
    Activity.LoadLayout("Layout1")
    lv.Clear
    Dim pm As PackageManager
    Dim packages As List
    packages = pm.GetInstalledPackages
    For i = 0 To packages.Size - 1
    Dim p As String = packages.Get(i)
        Dim bdw As BitmapDrawable = pm.GetApplicationIcon(p)
        lv.AddTwoLinesAndBitmap(pm.GetApplicationLabel(p),packages.Get(i),bdw.Bitmap)
        Log(packages.Get(i))
    Next

Edit: Now, I had noticed that it only happens for one application com.android.systemui
 
Last edited:
Upvote 0

wes58

Active Member
Licensed User
Longtime User
You can use a Try Catch block to skip this app.

Thanks Erel. I looked for the package name "com.android.systemui" and skipped it when it was in the the loop. But it will be safer to use try-catch as you suggested, just in case (in future) there are other applications with this problem.
 
Upvote 0
Top