有点不耐烦。
我想知道的是,如果某个应用程序不存在于设备上,它是否可以进入游戏商店下载。我知道我需要把这段代码放在
中Intent i = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(i);
但如果不存在,我可以让它去Play商店
答案 0 :(得分:9)
您可以使用以下某项功能检查是否已安装该应用。
功能1
private boolean isAppInstalled(String packageName) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
或功能2
public boolean isAppInstalled(String targetPackage){
List<ApplicationInfo> packages;
PackageManager pm = getPackageManager();
packages = pm.getInstalledApplications(0);
for (ApplicationInfo packageInfo : packages) {
if(packageInfo.packageName.equals(targetPackage)) return true;
}
return false;
}
<强> USAGE 强>
if(isAppInstalled("com.package.name")){
//Your Code
}
else{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.package.name")));
}