重定向至“从网站访问Android应用程序”诊断树
Redirect to Android App from a Website?
当用户打开网站时,我希望发生以下两种情况之一:
- 如果安装了应用程序mycolapp,则使用自定义url方案mycolapp将用户重定向到该应用程序://
- 如果未安装应用程序,请留在当前页面,而不发布或重定向到未知页面或弹出错误
情况1很容易你可以使用以下代码:
window.location = "mycoolapp://";
如果在设备上安装了应用程序,这将起作用。当应用程序未安装时,它会将用户重定向到未知的空白页面。
对于案例2,我有一个使用iFrame的解决方案,它在iOS和原生Android浏览器上运行良好。它在安卓版Chrome上不起作用。
var redirect = function (location) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', location);
iframe.setAttribute('width', '1px');
iframe.setAttribute('height', '1px');
iframe.setAttribute('position', 'absolute');
iframe.setAttribute('top', '0');
iframe.setAttribute('left', '0');
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
};
redirect('mycoolapp://');
当安装该应用程序时,它在本机Android浏览器上工作,但在Chrome for Android上没有重定向。页面上没有任何内容。
当应用程序未安装时,如何在不重定向到空白页面的情况下重定向到在Chrome for Android上运行的应用程序
编辑:我知道您可以使用Intent
window.location = "intent://#Intent;package=com.mycoolapp;scheme=mycoolapp;launchFlags=268435456;end;";
这不是我想要的,因为如果没有安装应用程序,它会在谷歌播放上启动应用程序页面。有没有一种方法不会重定向到谷歌播放?
Add this in manifest file,note the scheme.
<intent-filter>
<data android:scheme="startci" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
在html中给出代码,方案与清单文件中的方案相同。
<a href="intent:#Intent;scheme=startci;package=gramener.star;end">click here</a>
如果你想在你的应用程序中添加参数,请使用这个
<a href="intent:#Intent;scheme=startci://open?url_param=hi santhosh;package=gramener.star;end">click here</a>
如果应用程序没有安装,所以如果你想重定向到其他页面,请像这样添加回退url。url必须编码为
<a href="intent:#Intent;scheme=startci://open?url_param=hi santhosh;package=gramener.star;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end">click here</a>
要获得参数,请添加以下代码
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
if (data.getQueryParameter("url_param") != null) {
String param = data.getQueryParameter("url_param");
Log.d("the param is",param);
//do something here
}
}
您不需要根据自定义协议启动应用程序。它适用于任何地址,例如在您的AndroidManifest.xml
:中
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="www.mycoolapp.com" />
<data android:scheme="http" />
<data android:pathPattern="/Android" />
</intent-filter>
这意味着您可以使用引导用户
window.location = "/Android";
如果安装了应用程序,Android将提示"打开方式"。如果没有,用户将被带到浏览器中的/Android页面。
相关文章:
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在cordova android应用程序中连接数据库
- 使用javascript将视频从我的android应用程序上传到youtube
- 在Android网络应用程序中查找SD卡的路径
- GCM推送通知,如果应用程序在手机中关闭(Phonegap Android)
- Ionic应用程序无法识别android手机中的语音
- 我需要学习Java才能使用phoneGap创建android应用程序吗
- javascript onclick不适用于android应用程序
- 在变量中保存值的最佳方法是在应用程序关闭后使用,然后使用apachecordova在android中重新启动
- 如何通过ibmworklight中的sql适配器从db2中检索或显示html页面上的数据?android混合应用程序开发
- 带有Apache Cordova的Android应用程序
- 示例 WebView 应用程序源代码 Android
- Phonegap 3.2.0 android应用程序后退按钮剪切仅适用于某些页面
- D3图表未在Android混合应用程序中显示
- 如何在android应用程序中下载图像
- 无法从GCM(phonegap应用程序android)接收注册
- 用于打包移动应用程序(Android、iOS)的Javascript错误日志记录/报告/跟踪器
- 如何使用AngularJS创建移动应用程序(Android,IOS,Blockberry)
- 代码不工作的Phonegap应用程序-Android
- 制作一个安全的PhoneGap/Cordova应用程序(Android)