android - Android Chrome 自定义选项卡意图过滤器仅限于我的应用程序?
问题描述
我正在尝试在 Android 上实现https://mobikul.com/use-safariviewcontroller-callback-url-objective-c/,其中在 iOS 示例中检查了“sourceApplication”,并且只允许 SFSafariViewController 重定向回应用程序(大概它是由应用程序实例化的 SFSafariViewController ......但这是另一个问题!)。
我无法在 Android 中实现平等。在我的应用程序中,BrowserActivity
打开一个 Chrome 自定义选项卡,它CallbackActivity
从 HTML 重定向回。我发现,如果我输入正确的 URL 架构,Chrome / 手机上的任何浏览器也可以重定向回,这是个坏消息!CallbackActivity
清单中似乎应该有一个白名单机制,只允许从我的应用程序打开的 Chrome 自定义选项卡重定向回我的活动,而不允许其他任何人。我无法在清单中设置android:exported="false"
,CallbackActivity
因为这会破坏我的应用程序的重定向功能。如何实现这一目标?
这是我为 Android 清单准备的内容:
<activity android:name="com.epicgames.ue4.SplashActivity" android:launchMode="singleTask" android:debuggable="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.epicgames.ue4.GameActivity" android:exported="false">
<meta-data android:name="android.app.lib_name" android:value="UE4" />
</activity>
<activity android:name=".BrowserActivity" android:launchMode="singleTask" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity android:name=".CallbackActivity" android:launchMode="singleTask">
<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="customscheme" android:host="callback" />
</intent-filter>
以下是我对相关活动的了解:
public class BrowserActivity extends Activity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
final Uri uri = Uri.parse(getIntent().getStringExtra("url"));
final CustomTabsIntent intent = new CustomTabsIntent.Builder().build();
intent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.intent.setData(uri);
startActivity(intent.intent);
}
}
public class CallbackActivity extends Activity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
//TODO validate only chrome custom tab HTML, started from my app, redirected here
//getCallingPackage() is always null and referrer host can be spoofed...how to?
final Intent intent = new Intent(this, com.epicgames.ue4.GameActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
}
解决方案
推荐阅读
- python - 将 python 文件转换为可执行文件时会发生什么?
- java - 带有 spring-boot-starter-test 的 JUnit4 与 JUnit5
- wordpress - 在 WordPress 中插入标签
- java - 无法引用变量 - 找不到符号
- python-3.x - NOT NULL 约束失败:/jobs/add/ 处的jobs_job.created_by_id IntegrityError
- input - 如何在 LispWorks 中正确询问用户的输入?
- android - 在 recyclerview kotlin 中加载更多内容时如何不重写项目?
- javascript - Webpack 无法在已经工作的节点包中编译 js
- java - 检测到的 JDK 版本:15.0.2 不在允许范围内 [1.8.0-101,1.8.9999]
- python - 在等待响应 Flask Python 时防止重复提交表单