从网站重定向到Android应用程序? [英] Redirect to Android App from a Website?
问题描述
当用户打开网站时,我希望发生以下两种情况之一:
- 如果应用程序mycoolapp已安装重定向用户使用自定义URL方案mycoolapp://
- 将应用程序安装到应用程序如果应用程序未安装,则保留在当前页面上而不发布或重定向到未知页面或错误弹出窗口。 / li>
第1种情况很简单,您可以使用以下代码:
window.location =mycoolapp://;
如果应用程序安装在设备上,这将工作。当应用程序未安装时,它将用户重定向到未知的空白页面。
对于案例2,我有一个使用iFrame的解决方案,该解决方案在iOS和原生Android浏览器上都很出色。它不适用于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;
};
重定向('mycoolapp://');
当应用程序安装时,它正在使用原生Android浏览器,但在Android版Chrome上,不重定向。页面上没有任何反应。
如果我的应用无法在未安装应用时重定向到空白页, p> 编辑:我知道您可以使用Intent 这不是我想要的,因为如果应用程序未安装,它会在Google Play上启动应用程序页面。有没有一种方式,它不会重定向到谷歌播放? 你不需要 在自定义协议上启动您的应用程序。它适用于任何地址,例如在您的 这意味着您可以使用以下方式指导用户: 如果安装了应用程序,Android会提示打开方式。如果没有,用户将被带到浏览器中的/ Android页面。 When a user opens a website I want one of the following two cases to be happen: Case 1 is easy you can use the following code: This will work if the app is installed on the device. When the app is not installed it redirects the user to a blank page which is unknown. For case 2 I have a solution using an iFrame which works great on iOS and on the native Android browser. It does not work on Chrome for Android. When the app is installed it is working on the native Android browser, but on Chrome for Android there is not redirect. Nothing happens on the page. How can I make redirect to my app working on Chrome for Android without redirecting to a blank page when the app is not installed? Edit: I know that you can use an Intent This is not what I want because it launches the app page on google play if the app is not installed. Is there a way that it will not redirect to google play? You don't need to launch your app on a custom protocol. It will work for any address, e.g. in your This means you can direct the user using: If the app is installed, Android will prompt to "Open With". If not, the user will just be taken to the /Android page in their browser. 这篇关于从网站重定向到Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
window.location =intent://#Intent; package = com.mycoolapp; scheme = mycoolapp; launchFlags = 268435456; end;;
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;
window.location = "mycoolapp://";
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://');
window.location = "intent://#Intent;package=com.mycoolapp;scheme=mycoolapp;launchFlags=268435456;end;";
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";