3.Android框架层如何实现DeepLink?
上一篇提到Android使用DeepLink跳转有两种方式:Intent跳转、WebView网页跳转。这篇研究一下Android框架如何实现DeepLink。以下Android源代码分析版本为Android7.1。
(1)Intent跳转
这其实是一个Intent filter + start Activity的过程,使用的Intent Catagory是Intent.CATEGORY_BROWSABLE,从这入手。先在Android框架层代码中搜索一下看看哪些地方处理了Intent.CATEGORY_BROWSABLE?发现在处理Intent过滤的工具类中有处理:
frameworks/base/core/java/android/content/IntentFilter.java:
/**
* Return if this filter handles HTTP or HTTPS data URIs.
*
* @return True if the filter handles ACTION_VIEW/CATEGORY_BROWSABLE,
* has at least one HTTP or HTTPS data URI pattern defined, and optionally
* does not define any non-http/https data URI patterns.
*
* This will check if if the Intent action is {@link android.content.Intent#ACTION_VIEW} and
* the Intent category is {@link android.content.Intent#CATEGORY_BROWSABLE} and the Intent
* data scheme is "http" or "https".
*
* @param onlyWebSchemes When true, requires that the intent filter declare
* that it handles *only* http: or https: schemes. This is a requirement for
* the intent filter's domain linkage being verifiable.
* @hide
*/
public final boolean handlesWebUris(boolean onlyWebSchemes) {
// Require ACTION_VIEW, CATEGORY_BROWSEABLE, and at least one scheme
if (!hasAction(Intent.ACTION_VIEW)
|| !hasCategory(Intent.CATEGORY_BROWSABLE)
|| mDataSchemes == null
|| mDataSchemes.size() == 0) {
return false;
}
// Now allow only the schemes "http" and "https"
final int N = mDataSchemes.size();
for (int</