您不能檢查的天氣名單應用程序安裝或不從它的鏈接。包名是標識App所必需的。
要檢查App安裝或不使用以下功能。
public boolean appInstalledOrNot(Context context, String paramString) {
PackageManager localPackageManager = context.getPackageManager();
try {
//noinspection WrongConstant
localPackageManager.getPackageInfo(paramString, 1);
return true;
} catch (PackageManager.NameNotFoundException ignored) {
}
return false;
}
嘗試此開放原生應用
String facebookPackage = "com.facebook.katana";
if (appInstalledOrNot(this,facebookPackage)) {
String url = "https://m.facebook.com";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} else {
String url = "https://www.facebook.com";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
注:,如果你正在尋找的Facebook的包名和Twitter
com.facebook.katana - Facebook的
com.twitter.android - Twtter
當您在安裝應用程序時啓動'ACTION_VIEW'會發生什麼?你嘗試過'http'而不是'https'嗎? – JimmyB
包名是標識App所必需的。您無法從鏈接中檢查已安裝的天氣應用程序。 –
使用webview並設置其設置 –