Android Question PackageManager GetApplicationIcon

nibbo

Active Member
Licensed User
Longtime User
OK I have been trying this for about an hour and cannot see what I am doing that is different to any of the examples that I have looked at on this forum.
The following code crashes:
B4X:
    Dim pm As PackageManager
    Dim packageList As List = pm.GetInstalledPackages
    For i = 0 To packageList.Size - 1
        Dim packageName As String = packageList.Get(i)
        Dim appIntent As Intent
        appIntent = pm.GetApplicationIntent(packageName)
        If appIntent.IsInitialized Then
            Dim app As Application
            app.packageName = packageName
            app.ApplicationName=pm.GetApplicationLabel(packageName)
            app.Icon = pm.GetApplicationIcon(packageName)
            appList.Add(app)
        End If
    Next

It is the app.Icon = bit that fails and I get the error message java.lang.NullPointerException: expected receiver of type anywheresoftware.b4a.AbsObjectWrapper, but got null

app.Icon is a part of the following type:
B4X:
Type Application (PackageName As String, ApplicationName As String, Icon As BitmapDrawable)

Would really appreciate any assistance.
Thanks
 

nibbo

Active Member
Licensed User
Longtime User
Call app.Initialize after you declare app.

That simple... many thanks Erel.

Another issue is that the standard Navigation app is not listed.
I assume that this is because it is part of the Google Maps app rather than an app in its own right.
Is there a way to get a list of these?
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
pm.GetApplicationIcon returns the app's main activity. There can be many other "exported" activities in each app. It is more difficult to find other activities.

You can play with pm.QueryIntentActivities to find more activities.

Will do, thanks.
 
Upvote 0
Top