由网友(曲終人散)分享简介:我如何区分系统的应用程序和正常程序之间?我看了看,通过机器人 PackageManager ,找不到任何。编辑:我想通过code区分。如果(系统应用程序){//做一点事}其他{//没做什么}解决方案 您可以尝试使用在ApplicationInfo类(android.conent.pm)中提供的标志。例如:......
我如何区分系统的应用程序和正常程序之间?我看了看,通过机器人 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?
}
}
相关推荐
最新文章