android开发中,判断是否安装了qq

发布于2022-01-13 19:01:20
7个回答
admin
网友回答2022-01-13
Android系统中,判断应用有无安装有两种方式:
1.根据包名判断,以下为判断代码:
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}

2. 根据Intent判断,以下为判断代码:
public boolean checkApkExist(Context context, Intent intent) {
ListResolveInfo list = context.getPackageManager().queryIntentActivities(intent, 0);
if(list.size() 0){
return true;
}
return false;
}
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName)) return false;
try {
ApplicationInfo info = context.getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true;
} catch (NameNotFoundException e) { return false; }
}
public boolean checkApkExist(Context context, Intent intent) {
ListResolveInfo list = context.getPackageManager()
.queryIntentActivities(intent, 0);
if (list.size() 0) {
return true;
}
return false;
}
admin
网友回答2022-01-13
manifest.xml android:installLocation的值
admin
网友回答2022-01-13
因为你手机系统自带有一个QQ,没事的直接确定安装,或你把自带的那个删了,但手机必需root
admin
网友回答2022-01-13
没事,确定就行
admin
网友回答2022-01-13
通过反射得到ApplicationInfo源码中的installlocation这个Field,将你需要判断的appInfo传进去就OK了
admin
网友回答2022-01-13
manifest xmlns:android=http://schemas.android.com/apk/res/android
android:installLocation=preferExternal
...

installLocation有三个值可以选择:internalOnly、auto、preferExternal
选择preferExternal,系统会优先考虑将APK安装到SD卡上(当然最终用户可以选择为内部ROM存储上,如果SD存储已满,也会安装到内部存储上)

选择auto,系统将会根据存储空间自己去适应

选择internalOnly是指必须安装到内部才能运行
admin
网友回答2022-01-13
Android系统中,判断应用有无安装有两种方式:
1.根据包名判断,以下为判断代码:
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
2. 根据Intent判断,以下为判断代码:
public boolean checkApkExist(Context context, Intent intent) {
ListResolveInfo list = context.getPackageManager().queryIntentActivities(intent, 0);
if(list.size() 0){
return true;
}
return false;
}
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName)) return false;
try {
ApplicationInfo info = context.getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true;
} catch (NameNotFoundException e) { return false; }
}
public boolean checkApkExist(Context context, Intent intent) {
ListResolveInfo list = context.getPackageManager()
.queryIntentActivities(intent, 0);
if (list.size() 0) {
return true;
}
return false;
}

回到
顶部