Dai*_*run 3 redirect android webview google-oauth google-oauth2
我需要打开自定义Chrome标签,将用户带到我的网站,然后将用户重定向回应用.它类似于为OAuth启动页面.
这是Android方面的样子......
AndroidManifest.xml(将意图过滤器添加到用于侦听URI的活动)
<activity android:name=".app.MyActivity"
android:label="@string/title"
android:theme="@style/AppTheme"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mytest" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
Activity.java(启动自定义chrome选项卡)
private void goToSite() {
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
int toolbarColor = getResources().getColor(R.color.primary);
intentBuilder.setToolbarColor(toolbarColor);vice_key(), shared().getAccessToken());
intentBuilder.build().launchUrl(this, Uri.parse("https://example.com/some-page"));
}
Run Code Online (Sandbox Code Playgroud)
在我的服务器上,用户完成一个表单并最终被带到一个页面,该页面应该将它们重定向回应用程序...
server.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Redirecting...</title>
<script>
var redirectToApp = function() {
setTimeout(function appNotInstalled() {
window.location.replace("http://example.com/app-not-installed");
}, 100);
window.location.replace("mytest://justanexample");
};
window.onload = redirectToApp;
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
但我没有被重定向到应用程序.我怀疑我的服务器代码有问题,因为类似的设置(清单和活动代码)在处理OAuth页面时有效.我的服务器代码有什么问题?我该如何解决这个问题?
编辑
Android端似乎是正确的 - 更改服务器代码<a href="mytest://other/parameters/here">GO TO APP</a>似乎工作,但我需要一种不涉及单击链接的方法
编辑2
上面的代码实际上有效:/
因为我在Chrome自定义标签中,我正在重定向到我已经在的页面(因为Chroms自定义标签活动被视为应用内).这让我觉得没有重定向发生.特里斯坦的评论让我意识到了这一点
您可以简单地使用Javascript,如本答案中所述.
基本上你会与一个人建立联系
<a href="intent://example.com#Intent;scheme=http;package=com.example.mypackage;end">
Run Code Online (Sandbox Code Playgroud)
package =您的包名称
有关更多信息,请参阅此问题从网页打开Android应用程序
| 归档时间: |
|
| 查看次数: |
2378 次 |
| 最近记录: |