简体   繁体   English

如何将用户从移动应用重定向到移动Web浏览器?

[英]How to redirect user to mobile web browser from mobile app?

Our app lets users login into other services. 我们的应用程序使用户可以登录其他服务。 A user clicks on a Login button on a website (in some mobile browser) or on another app, which takes them to our app through a deep link. 用户单击网站(在某些移动浏览器中)或另一个应用程序上的“登录”按钮,这将通过深层链接将其带到我们的应用程序。 The user completes the login flow in our app. 用户完成了我们应用程序中的登录流程。 We'd then like to automatically redirect the user to where they started from, whether on a mobile browser or another app. 然后,我们希望将用户自动重定向到他们从哪里开始,无论是在移动浏览器还是其他应用程序上。 I can't figure out how to do this in the general case. 在一般情况下,我不知道如何执行此操作。

My understanding is that redirecting to another app requires that app to have deep linking enabled. 我的理解是,重定向到另一个应用程序需要该应用程序启用深度链接。 (Question #0: Is this true, or is there a way to do this even if the app doesn't have deep linking?) (问题0:是真的,还是即使应用没有深层链接也有办法做到这一点吗?)

Everyone I've asked seems to think this is only possible for apps and not mobile browsers, ie that there is no way to deep link into mobile browsers or otherwise redirect the user to them (except to the phone's default browser). 我问过的每个人似乎都认为这仅适用于应用程序,而不适用于移动浏览器,即,无法深入链接到移动浏览器或以其他方式将用户重定向到它们(手机的默认浏览器除外)。 But this doesn't make sense to me, since a mobile browser is just a kind of mobile app. 但这对我来说没有意义,因为移动浏览器只是一种移动应用程序。

Also, there's at least an OS-level way to go back to another app or browser: both iOS and Android have such a back button, and it works with apps (even if they don't have deep linking) and mobile browsers. 而且,至少有一种操作系统级别的方法可以返回到另一个应用程序或浏览器:iOS和Android都具有这样的后退按钮,并且可以与应用程序(即使它们没有深层链接)和移动浏览器一起使用。 I don't know if this is accessible to us developers, but it suggests that the functionality might be possible. 我不知道我们的开发人员是否可以使用此功能,但这表明该功能可能可行。

Someone suggested to me that there was some way to redirect a user to an app by using something like com.appName , but I haven't been able to find anything online to support this. 有人向我建议,可以使用com.appName类的方法将用户重定向到应用程序,但是我一直无法在线找到任何支持此功能的方法。

To make this clearer, here's an example of a desired flow that captures the more subtle challenges: 为了更清楚地说明这一点,下面是一个示例流程,该流程捕获了更微妙的挑战:

Example 1. The user is using the Brave mobile browser, which is not their phone's default browser. 示例 1.用户正在使用Brave移动浏览器,这不是手机的默认浏览器。 2. On some website, they click a Login button that takes them to our app, where they finish the login flow. 2.在某些网站上,他们单击“登录”按钮,将他们带到我们的应用程序,并在此完成登录流程。 3. Our app takes them back to Brave, where they website the button was on updates to reflect the fact that they've completed the login process. 3.我们的应用程序将他们带回到Brave,在他们的网站上该按钮处于更新状态,以反映他们已完成登录过程的事实。

You can URL in the mobile browser using Intent . 您可以使用Intent在移动浏览器中输入URL。

String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
//Or
//Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);

You can also open specific browsers using something along the following lines. 您还可以使用以下几行内容来打开特定的浏览器。

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setPackage("com.android.chrome");
try {
    startActivity(i);
} catch (ActivityNotFoundException e) {
    // Chrome is probably not installed
    // Try with the default browser
    i.setPackage(null);
    startActivity(i);
}

You could also allow the user to choose the browser. 您还可以允许用户选择浏览器。

String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// Note the Chooser below. If no applications match, 
// Android displays a system message.So here there is no need for try-catch.
startActivity(Intent.createChooser(intent, "Browse with"));

Here's the link to the official docs for further reference. 这是官方文档的链接,以供进一步参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将用户从移动浏览器重定向到应用程序(android 和 ios) - How to redirect user from mobile browser to Apps (android & ios) 从网页重定向到移动应用 - Redirect to a mobile app from a web page 将网站从 facebook web 浏览器重定向到手机的默认浏览器 - Redirect website from facebook web browser to mobile's default browser 将用户从移动网站重定向到专用的移动应用 - Redirect user from mobile website to dedicated mobile app 移动应用程序使用登录用户无缝打开 web 浏览器 - Mobile app seamlessly open web browser with logged in user 将按钮从移动浏览器重定向到手机上的消息传递应用程序 - Redirect a button from a mobile browser to a messaging app on phone 启用移动网络应用以在用户移动默认浏览器中打开链接,而不是在应用内部打开 - Enable mobile web app to open a link in user mobile default browser instead of opening inside the app 如何将参数从浏览器传递到移动应用 - How to pass parameter from browser to mobile app 在浏览器中的Webview中打开Facebook Mobile Web App - Open Facebook Mobile Web App in webview from browser 从移动网络浏览器(Chrome)启动Aurasma和QR扫描仪应用程序 - Launching the Aurasma & QR Scanner app from mobile web browser (Chrome)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM