我有一个用于打开手机浏览器的应用程序,用户将被重定向到我的webapp,在某个用户操作后,webapp会使用intent过滤器重定向回应用程序
<application>
<activity
android:name="com.xyz.sdk.SomeActivity"
android:allowTaskReparenting="true"
android:configChanges="keyboardHidden|orientation|keyboard|screenSize"
android:launchMode="singleTask"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<data android:scheme="someString-${applicationId}" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
最近我迁移到使用Chrome自定义标签而不是浏览器(出于安全考虑,Webview不是一个选项)
不幸的是,当在Chrome自定义标签中重定向回应用时,Chrome自定义标签页不会自动关闭.即使我可以通过日志验证应用程序已收到响应,自定义选项卡仍保持打开并保持在最顶层,因此用户无法看到应用程序上发生的更新,直到他关闭应用程序.
我发现一个解决方法是在启动我的自定义选项卡时设置NEW_TASK标志,但这使我的应用程序和自定义选项卡显示为两个单独的应用程序,这是我首先从浏览器中移开的全部原因.
总结:我有App A,它打开一个自定义选项卡,在自定义选项卡中打开的webapp使用intent过滤器重定向回App A,但vustom选项卡不会关闭并保持在顶部,直到用户手动关闭它.
我已经尝试为自定义选项卡意图设置NO_HISTORY标志但它没有任何区别.
自定义标签代码:
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(getToolBarColor())
.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.build();
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.launchUrl(this, Uri.parse(url));
customTabsIntent.launchUrl(this, Uri.parse(url));
Run Code Online (Sandbox Code Playgroud)
更新 我已经意识到如果意图过滤器重定向回到另一个应用程序,那么自定义选项卡成功关闭(假设它是一个单一活动并且没有历史记录设置为true)但在我的情况下,我们需要重定向回相同的活动从中调用自定义选项卡.
我有一个chrome自定义选项卡,但我想在标题栏左上角的关闭(X)按钮中添加一个监听器.
我想在每次用户点击关闭按钮时触发回调.
我能够在Web视图中执行此操作,但无法确定是否可以使用chrome自定义选项卡.
这是我用来调用自定义标签的代码段:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.enableUrlBarHiding();
builder.setToolbarColor(getTitleBarBackgroundColor());
builder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
builder.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
customTabsIntent = builder.build();
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
customTabsIntent.launchUrl(this, Uri.parse(url));
Run Code Online (Sandbox Code Playgroud)