有点艰难。
我想知道的是,如果一个应用程序在设备上不存在,它能否进入Play商店下载。我知道我需要放入这段代码:
Intent i = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(i);
如果没有这个选项,我能否让它跳转到Play商店?
有点艰难。
我想知道的是,如果一个应用程序在设备上不存在,它能否进入Play商店下载。我知道我需要放入这段代码:
Intent i = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(i);
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;
}
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;
}
使用说明
if(isAppInstalled("com.package.name")){
//Your Code
}
else{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.package.name")));
}
com.package.name
应该被替换为com.package.address
。 - Sunil Mishra