Android Code Snippet isSystemapp

Discussion in 'Code Snippets' started by DonManfred, Dec 27, 2014.

  1. DonManfred

    DonManfred Expert Licensed User

    SubName: isSystemapp

    Description: Check whether the given name is a Systemapp or not

    Sub isSystemapp(app As StringAs 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""' List<PackageInfo>
      For i = 0 To Obj1.RunMethod("size") -1
          Obj2.Target = Obj1.RunMethod2(
    "get", i, ""' 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
    ' Systemapp
                    result = True
    End If   
    End If
    Return result
    End Sub
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **

    Dependencies: Reflection

    Tags: Packagemanager, Systemapp
  2. LucaMs

    LucaMs Expert Licensed User

    I enjoyed the "Spoiler": will have someone suspected that Whatsapp was a system app? :) (note: I do not have it anymore).
  3. DonManfred

    DonManfred Expert Licensed User

    lol. No, not really... I just needed to pickup two apps to show how it works... for the systemappsample i used one that should be known by everyone ( and for the other one i just used Whatsapp as i got a message in that moment in Whatsapp :D
    lemonisdead likes this.
  4. LucaMs

    LucaMs Expert Licensed User

    Sure, I get it, and you have chosen well... the strange thing is that you used the Spoiler... I think you did it because you enjoy it :)
    DonManfred likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice