我怎样才能动态地检测我的应用程序是否是系统还是正常的吗? [英] How can I dynamically detect whether my application is system or normal?

查看:177
本文介绍了我怎样才能动态地检测我的应用程序是否是系统还是正常的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何区分系统的应用程序和正常程序之间?我看了看,通过机器人 PackageManager ,找不到任何。

编辑:我想通过code区分

 如果(系统应用程序){
  //做一点事
}
其他{
   //没做什么
}
 

解决方案

您可以尝试使用在ApplicationInfo类(android.conent.pm)中提供的标志。例如:

  ...
PackageManager下午= getPackageManager();
名单< ApplicationInfo> installedApps = pm.getInstalledApplications(0);

对于(ApplicationInfo AI:installedApps){

    如果((ai.flags&安培;!ApplicationInfo.FLAG_SYSTEM)= 0){
        //系统应用程序 - 这样做的东西在这里
        ...
    } 其他 {
        //用户安装的应用程序?
    }
}
 

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 to differentiate via code.

if(system app) {
  //do something
}
else{
   //do nothing
}

解决方案

You could try using the flags available in the ApplicationInfo class (android.conent.pm). For example:

...
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);

for (ApplicationInfo ai: installedApps) {

    if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        // System app - do something here
        ...
    } else {
        // User installed app?
    }
}

这篇关于我怎样才能动态地检测我的应用程序是否是系统还是正常的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆