How can I dynamically detect whether my application is system or normal?

前端 未结 5 2087
失恋的感觉
失恋的感觉 2021-02-14 11:53

How do I differentiate between a system app and a normal app ? I looked through android PackageManager and could not find any.

Edit: I want

5条回答
  •  情书的邮戳
    2021-02-14 12:22

    Forget PackageManager! You only asked about your own application. Within your Activity#onCreate(Bundle) you can just call getApplicationInfo() and test its flags like this:

    boolean isSystemApp = (getApplicationInfo().flags
      & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    

提交回复
热议问题