SubName: isSystemapp
Description: Check whether the given name is a Systemapp or not
Example
Dependencies: Reflection
Tags: Packagemanager, Systemapp
Description: Check whether the given name is a Systemapp or not
B4X:
Sub isSystemapp(app As String) As Boolean
Dim Obj1, Obj2, Obj3 As Reflector
Dim size, i, flags As Int
Dim result As Boolean = False
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod("getPackageManager") ' PackageManager
Obj1.Target = Obj1.RunMethod2("getInstalledPackages", 0, "java.lang.int") ' List<PackageInfo>
For i = 0 To Obj1.RunMethod("size") -1
Obj2.Target = Obj1.RunMethod2("get", i, "java.lang.int") ' PackageInfo
Dim name As String = Obj2.GetField("packageName")
If app.ToLowerCase = name.ToLowerCase Then
Obj3.Target = Obj2.GetField("applicationInfo") ' ApplicationInfo
flags = Obj3.GetField("flags")
If Bit.AND(flags, 1) = 0 Then
'app is not in the system image
Else
' Systemapp
result = True
End If
End If
Next
Return result
End Sub
Example
B4X:
Log("isSystemapp(com.whatsapp):"&isSystemapp("com.whatsapp"))
Log("isSystemapp(com.android.phone):"&isSystemapp("com.android.phone"))
** Activity (main) Create, isFirst = true **
isSystemapp(com.whatsapp):false
isSystemapp(com.android.phone):true
** Activity (main) Resume **
isSystemapp(com.whatsapp):false
isSystemapp(com.android.phone):true
** Activity (main) Resume **
Dependencies: Reflection
Tags: Packagemanager, Systemapp