gpt4 book ai didi

javascript - 如何检测安装在任何浏览器手机中的应用程序 android 或 iOS?

转载 作者:行者123 更新时间:2023-11-29 02:47:30 25 4
gpt4 key购买 nike

如何检测安装在任何浏览器移动设备上的 Android 或 iOS 应用程序???

示例:当我转到地址 http://news.zing.vn 时,如果应用程序没有安装,一个警告将显示这样的消息“应用程序 xxx 在商店中可用。立即安装。”

如果选择确定,手机将使用我的应用程序打开 Play Store(Android) 或 AppStore(iOS)。如果选择取消,浏览器将保存 cookie,下次不会显示警报。

抱歉我的英语不好!!!

最佳答案

看看有没有帮助

if(CheckNetwork.isInternetAvailable(getActivity())) //returns true if internet available
{
boolean chrome_status = appInstallationStatus("com.android.chrome");
if(chrome_status) {
//This intent will help you to launch if the package is already installed
Log.i("App already installed on your phone");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Info");
builder.setMessage("Google Chrome is the preferred browser. For best performance please select Chrome")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();

Intent intent = new Intent(getActivity(), MyActivity.class);
startActivity(intent);
}
});
builder.create();
builder.show();
}
else {
Log.i("App is not installed on your phone");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Info")
.setMessage("No Google Chrome found. Chrome is the preferred browser. Do you want to install it ?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+"com.android.chrome&hl=en")));
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

dialog.cancel();
Intent intent = new Intent(getActivity(), MyActivity.class);
startActivity(intent);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
}
else {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
alertDialog.setTitle("Network Error");
alertDialog.setMessage("No network connectivity. Please try again later!");
alertDialog.setPositiveButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

}
});
alertDialog.create().show();
}

否则尝试查看此链接。 Detect from browser if a specific application is installed in Android

关于javascript - 如何检测安装在任何浏览器手机中的应用程序 android 或 iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24925251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com