android 区分系统应用,Android区分系统应用和安装应用
獲取全部包信息:
/**
*
* 獲取系統(tǒng)中的全部包信息
*
* @param context 應(yīng)用上下文
*
*/
privatevoidgetPackageInfos(Context context) {
PackageManager pm = context.getPackageManager();
List packageInfos = pm.getInstalledPackages(0);
for(PackageInfo packageInfo : packageInfos) {
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
String packageName = packageInfo.packageName;
if(isSystemApp(applicationInfo)) {
Log.i("弗洛拉鮮花", "系統(tǒng)應(yīng)用:"+ packageName);
} else{
Log.i("弗洛拉鮮花", "安裝應(yīng)用:"+ packageName);
}
}
/**
*
* 獲取系統(tǒng)中的全部包信息
*
* @param context 應(yīng)用上下文
*
*/
private void getPackageInfos(Context context) {
PackageManager pm = context.getPackageManager();
List packageInfos = pm.getInstalledPackages(0);
for (PackageInfo packageInfo : packageInfos) {
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
String packageName = packageInfo.packageName;
if (isSystemApp(applicationInfo)) {
Log.i("弗洛拉鮮花", "系統(tǒng)應(yīng)用:" + packageName);
} else {
Log.i("弗洛拉鮮花", "安裝應(yīng)用:" + packageName);
}
}
}
方法1:
/**
*
* 判斷是否為系統(tǒng)應(yīng)用程序
*
* @param appInfo 應(yīng)用程序
*
* @return
*
*/
@SuppressWarnings("static-access")
privatebooleanisSystemApp(ApplicationInfo appInfo) {
return(appInfo.flags & appInfo.FLAG_SYSTEM) >0;
}
/**
*
* 判斷是否為系統(tǒng)應(yīng)用程序
*
* @param appInfo 應(yīng)用程序
*
* @return
*
*/
@SuppressWarnings("static-access")
private boolean isSystemApp(ApplicationInfo appInfo) {
return (appInfo.flags & appInfo.FLAG_SYSTEM) > 0;
}方法2:
/**
*
* 判斷是否為系統(tǒng)應(yīng)用程序
*
* @param appInfo 應(yīng)用程序
*
* @return
*
*/
privatebooleanisSystemApp(ApplicationInfo appInfo) {
/**
* uid是應(yīng)用程序安裝時(shí)由系統(tǒng)分配(1000 ~ 9999為系統(tǒng)應(yīng)用程序保留)
*/
returnappInfo.uid >1000;
}
總結(jié)
以上是生活随笔為你收集整理的android 区分系统应用,Android区分系统应用和安装应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 设置默认铃声,Andro
- 下一篇: HTML自动获取地址,网页中自动获取经纬