Custom URL scheme 的好处就是,你可以在其它程序中通过这个url打开应用程序。如A应用程序注册了一个url scheme:myApp, 那么就在mobile浏览器中就可以通过打开你的应用程序A。
Android
首先在AndroidManifast.xml要被指定Scheme的Activity下设置如下参数
这样即指定了接收Uri的Scheme为 mgtv 且 Action为View的Intent。
利用如下Intent调用Activity
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("mgtv://?action=play&data=12345")));
或在浏览器中调用A链接打开
打开你的应用程序
在接收的Activity中使用如下代码获得数据
//获得Scheme名称
this.getIntent().getScheme();
//获得Uri全部路径
this.getIntent().getDataString();
iOS
如果没有URL types,随意点一个key行后面+号,输入大写URL选择URL types
右键URL types,选择add row
item0下改成url identifier,后面的value值随意写,com.xx,xx