android-Scheme
来源:互联网 发布:数控编程东方明珠图 编辑:程序博客网 时间:2024/06/06 00:54
参考:Android业务组件化之URL Scheme使用
什么是 URL Scheme?
android中的scheme是一种页面内跳转协议,是一种非常好的实现机制,通过定义自己的scheme协议,可以非常方便跳转app中的各个页面;通过scheme协议,服务器可以定制化告诉App跳转那个页面,可以通过通知栏消息定制化跳转页面,可以通过H5页面跳转页面等。
URL Scheme应用场景:
客户端应用可以向操作系统注册一个 URL scheme,该 scheme 用于从浏览器或其他应用中启动本应用。通过指定的 URL 字段,可以让应用在被调起后直接打开某些特定页面,比如商品详情页、活动详情页等等。也可以执行某些指定动作,如完成支付等。也可以在应用内通过 html 页来直接调用显示 app 内的某个页面。综上URL Scheme使用场景大致分以下几种:
服务器下发跳转路径,客户端根据服务器下发跳转路径跳转相应的页面
H5页面点击锚点,根据锚点具体跳转路径APP端跳转具体的页面
APP端收到服务器端下发的PUSH通知栏消息,根据消息的点击跳转路径跳转相关页面
APP根据URL跳转到另外一个APP指定页面
URL Scheme协议格式:
String urlStr="http://www.orangecpp.com:80/tucao?id=hello&name=lily";//url = protocol + authority(host + port) + path + query//协议protocol= http//域名authority= www.orangecpp.com:80//页面path= /tucao//参数query= id=hello&name=lily//authority = host + port//主机host= www.orangecpp.com//端口port= 80
URL Scheme如何使用:
1.)设置Scheme
在AndroidManifest.xml中对标签增加设置Scheme
<activity android:name=".GoodsDetailActivity" android:theme="@style/AppTheme"> <!--要想在别的App上能成功调起App,必须添加intent过滤器--> <intent-filter> <!--协议部分,随便设置--> <data android:scheme="xl" android:host="goods" android:path="/goodsDetail" android:port="8888"/> <!--下面这几行也必须得设置--> <category android:name="android.intent.category.DEFAULT"/> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> </intent-filter></activity>
2.)获取Scheme跳转的参数
Uri uri = getIntent().getData();if (uri != null) { // 完整的url信息 String url = uri.toString(); Log.e(TAG, "url: " + uri); // scheme部分 String scheme = uri.getScheme(); Log.e(TAG, "scheme: " + scheme); // host部分 String host = uri.getHost(); Log.e(TAG, "host: " + host); //port部分 int port = uri.getPort(); Log.e(TAG, "host: " + port); // 访问路劲 String path = uri.getPath(); Log.e(TAG, "path: " + path); List<String> pathSegments = uri.getPathSegments(); // Query部分 String query = uri.getQuery(); Log.e(TAG, "query: " + query); //获取指定参数值 String goodsId = uri.getQueryParameter("goodsId"); Log.e(TAG, "goodsId: " + goodsId);}
3.)调用方式
网页上
<a href="xl://goods:8888/goodsDetail?goodsId=10011002">打开商品详情</a>
原生调用
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("xl://goods:8888/goodsDetail?goodsId=10011002"));startActivity(intent);
4.)如何判断一个Scheme是否有效
PackageManager packageManager = getPackageManager();Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("xl://goods:8888/goodsDetail?goodsId=10011002"));List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);boolean isValid = !activities.isEmpty();if (isValid) { startActivity(intent);}
阅读全文
0 0
- scheme Android
- android-Scheme
- android:scheme 的问题
- 【Android】Scheme详解
- Android URL scheme
- Android中的URL Scheme
- Android URL Scheme 学习
- Android 自定义URL Scheme
- Android Intent Scheme URLs攻击
- Android中Scheme跳转协议
- Android APK Signature Scheme v2
- Android URL Scheme协议使用
- Android APK Signature Scheme v2
- Android之URL Scheme使用
- Android 通过scheme跳转界面
- scheme
- Scheme
- Scheme
- 人工智能将改变我们变老的方式
- AI有可能了解人类感情吗?
- 本地编译 gulp 项目
- Dataguard日常维护及故障解决
- <mvc:annotation-driven/>作用
- android-Scheme
- C# Winform Socket 即时通讯 (客户端+服务端)
- Django 模板继承
- C语言预习预处理
- 单元格点击事件
- linux 查看系统版本
- Vue.js+Django+Gunicorn+Python3+Nginx+Ubuntu16.04
- ubuntu 14.04环境下执行adb shell 时报错 error: device not found.的解决方法
- Mac OSX 安装phpredis最详细步骤