用户在访问我们的网页时,判断出这个用户手机上是否安装了我们的App,如果安装了则直接从网页上打开APP,否则就引导用户前往下载,从而形成一个推广上的闭环。这里只针对从网页端打开本地APP。
将一组APP设置一个统一的入口,然后根据实际需要在调用不同子APP,即所谓的APP业务组件化,URL Scheme在其中有着重要的作用。
Url scheme和Android intent唤起APP- https://blog.csdn.net/qq_23089525/article/details/52769315
第三方应用通过Schema协议打开APP- https://github.com/zhufeng1222/SchemaLoadAPP
> Android的深度链接技术Deep Links 或 App Links
-- Deep Links 遇到的坑
1.scheme为htttp/https 开头的uri,在有的浏览器或者手机ROM中并不能链接至APP,而是在浏览器中打开了对应的链接。所以做Deep Links时建议全部采用自定义Scheme的形式。
2.在询问是否用APP打开对应的链接时,如果选择了“取消”并且“记住选择”被勾上,那么下次你再次想链接至APP时就不会有任何反应!!!
3.不同的host不要写在同一个Intent Filter中,最好为每种匹配规则新建一个Intent Filter
-- App Links实现
,Android Studio 2.3 特性:生成Android App Links
在AndroidManifest中添加Intent Filters
<activity ...>
<intent-filter android:autoVerify="true">
<!-- action 和category 必须这样写!!! -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="yaoyi.ypzdw.com" />
<data android:scheme="https" android:host="yaoyi.ypzdw.com" />
</intent-filter>
</activity>
这里的Intent Filter和Deep Links 有点像,但是要注意,这里的Scheme只能用 http/https或者两个都用,但是 不能使用自定义的scheme!不能使用自定义的scheme!不能使用自定义的scheme!重要的事说三遍
android:autoVerify="true" 这句会让APP自动在所列的host中去验证,如果验证成功,APP将成为匹配URI默认打开方式
使用App Links能为开发者带来福利,但目前仍然有几个不可忽视的缺陷:
当app配置好了对App Links的支持之后,只有运行在Android M上的用户才能直接体会到这项好处
开发者需要维护与App相关联的站点,并支持上传认证文件,可能造成更大的财力精力开销
> Android使用URL Scheme/ host/ path/ port调起APP
方法一:App A打开App B(原生App使用Scheme调起App)
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://baidu:8080/news?system=pc&id=45464"));
startActivity(intent);
方法二:(在WebView中调起App)
<a href="http://baidu:8080/news?system=pc&id=45464">test</a>
(<a href="xl://goods:8888/goodsDetail?goodsId=10011002">打开商品详情</a>)
<activity
android:name="com.example.helloworld.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="http" android:host="baidu" android:path="/news" android:port="8080"/>
</intent-filter>
</activity>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String scheme = intent.getScheme();
String dataString = intent.getDataString();
Uri uri = intent.getData();
System.out.println("scheme:" + scheme);
if (uri != null) {
//完整的url信息
String url = uri.toString();
//scheme部分
String schemes = uri.getScheme();
//host部分
String host = uri.getHost();
//port部分
int port = uri.getPort();
//访问路径
String path = uri.getPath();
//编码路径
String path1 = uri.getEncodedPath();
//query部分
String queryString = uri.getQuery();
//获取参数值
String systemInfo = uri.getQueryParameter("system");
String id=uri.getQueryParameter("id");
System.out.println("host:" + host);
System.out.println("dataString:" + dataString);
System.out.println("id:" + id);
System.out.println("path:" + path);
System.out.println("path1:" + path1);
System.out.println("queryString:" + queryString);
}
}
}