Android Question time to read application label ?

hookshy

Well-Known Member
Licensed User
Longtime User
I did succeded to read all the installed packages and get then the application lable using package manager ... problem is that reading all labels take a lifetime ...
If the time is not critical then it should be no problem diplaying all but sometimes 5,6 seconds is a lifetime.
Is there any way to fasten this process ?

B4X:
Dim appl As List
appl.Initialize
appl=getLauncherApplications

for i=0 to appl.size-1

dim plabel ,pname as string
pname=appl.get(i)
plabel=pm.GetApplicationLabel(pname) 'where pm is package manager

next

Sub getLauncherApplications As List
    Dim intnt As Intent
    Dim ref As Reflector
    Dim lst As List
    Dim result As List

    intnt.Initialize(intnt.ACTION_MAIN, "")
    intnt.AddCategory("android.intent.category.LAUNCHER")
    ref.Target = getPackageManager
    'public abstract List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
    Dim args(2) As Object
    Dim types(2) As String
    args(0) = intnt
    args(1) = 0
    types(0) = "android.content.Intent"
    types(1) = "java.lang.int"
    lst = ref.RunMethod4("queryIntentActivities", args, types) 'List<ResolveInfo>

    result.Initialize
    For Each resolveInfo As Object In lst
        ref.Target = resolveInfo
        ref.Target = ref.GetField("activityInfo")
        result.add(ref.GetField("applicationInfo"))
    Next
    Return result
End Sub
 

HotShoe

Well-Known Member
Licensed User
Longtime User
This seems to work well for my filemanager app.

B4X:
Sub pkgbtn_Click
    Dim sb As StringBuilder
    Dim bmp As BitmapDrawable
    Dim tst, tst1 As String
    Dim mgr As PackageManager 'phone library
    Dim i As Int
   
    sb.Initialize
    pack.Initialize 'list
   
    If Not(pkgpan.IsInitialized) Then 'loads a layout file containing the listview pkglist
    Activity.LoadLayout("pkg")
   
    End If
   
    pkglst.Clear 'listview
    pkgpan.Visible = True 'the main panel of the loaded layout
    pkgpan.BringToFront
   
    ProgressDialogShow("Gathering package information")
    DoEvents
   
    pack = mgr.GetInstalledPackages
    pack.SortCaseInsensitive(True)
   
    For i = 0 To pack.Size - 1
    sb.Remove(0, sb.Length)
   
    Try
    bmp = mgr.GetApplicationIcon(pack.get(i))
    Catch
    Log(LastException.Message)
    End Try
   
    sb.Append(pack.get(i))
   
    tst = sb.ToString.Trim
    gi = pkglst.width / 12dip
   
    Do While tst.Length > gi
   
    tst = tst.SubString2(0,tst.Length - 2)
    Loop
   
    Try
    tst1 = mgr.GetVersionName(sb.ToString).Trim
    Catch
    Log(LastException.Message)
    End Try
   
    If bmp <> Null Then
    pkglst.AddTwoLinesAndBitmap(tst, tst1, bmp.Bitmap)
    Else
    pkglst.AddTwoLines(tst, tst1)
    End If
   
    Next
   
    ProgressDialogHide
   
End Sub

--- Jem
 
Upvote 0
Top