Android Question order and limit application list

fanfalveto

Active Member
Licensed User
Longtime User
i have with this a list with the applications instaled.
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private ls As ListView
Dim list1 As List
Dim pm As PackageManager
    Dim Packages As List   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("voz")
vamos
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub vamos
Dim icon As BitmapDrawable
Dim AppPckgName As String
list1.Initialize
Packages.Initialize   
    Packages = pm.GetInstalledPackages   
'    icon.InitializeMutable(48dip,48dip)
                For i = 0 To Packages.Size - 1   
                AppPckgName = Packages.Get(i)
icon=pm.GetApplicationIcon(AppPckgName)
                  ls.AddTwoLinesAndBitmap(pm.GetApplicationLabel(Packages.Get(i)),Packages.get(i),icon.Bitmap)               
                               list1.Add(Packages.Get(i))
                Next
                ls.FastScrollEnabled = True   
End Sub

Sub ls_ItemClick (Position As Int, Value As Object)
  Dim i As Intent   
    i.Initialize(list1.Get(Position),"")
                i = pm.GetApplicationIntent(list1.Get(Position))
                Try
                StartActivity(i)   
                Catch
                ToastMessageShow("no se puede",False)
                End Try
End Sub

Sub ls_ItemLongClick (Position As Int, Value As Object)
Dim i As Intent
  i.Initialize("android.intent.action.DELETE", "package:" & list1.Get(Position))
  StartActivity(i)
End Sub
the problem is the order of the listview and i want only see applicatons instaled by the user not system applications.
Any idea?
Thank you
 

NJDude

Expert
Licensed User
Longtime User
Try this code:
B4X:
Sub Info 'User Apps only 

    Dim Obj1, Obj2, Obj3 As Reflector
    Dim size, flags As Int
    Dim name As String
                
    Obj1.Target = Obj1.GetContext
    Obj1.Target = Obj1.RunMethod("getPackageManager")
    Obj1.Target = Obj1.RunMethod2("getInstalledPackages", 0, "java.lang.int")

    size = Obj1.RunMethod("size")

    For I = 0 To size -1

        Obj2.Target = Obj1.RunMethod2("get", I, "java.lang.int")
        name = Obj2.GetField("packageName")
        Obj3.Target = Obj2.GetField("applicationInfo")
    
        flags = Obj3.GetField("flags")

        If Bit.AND(flags, 128) <> 0 OR Bit.AND(flags, 1) = 0 Then

            ListView1.AddSingleLine(name)   '<-- Your ListView here
												
        End If

    Next
				
End Sub
 
Upvote 0
Top