Android 中Scheme协议的使用详解
1. 什么是URL Scheme?
简单的说就是android中的一种页面内跳转协议,方便app页面的内的跳转
2.什么时候使用
- 服务器下发跳转路径,客户端根据 服务器下发跳转路径跳转相应的页面
- H5页面点击描点,根据描点具体跳转路径APP端跳转具体的页面
- APP端收到服务器端下发的PUSH通知栏消息,根据消息的点击跳转路径跳转相关页面
- APP根据URL跳转到另外一个APP指定页面
3.协议格式
zymobi://3g2win:9999/macthDetail?macthId=222&time=10001
复制代码
scheme |
代表该Schema 协议名称 |
zymobi |
host |
代表Schema作用于哪个地址域 |
3g2win |
port |
代表该路径的端口号 |
9999 |
path |
代表Schema指定的页面 |
/macthDetail |
-- |
代表传递的参数 |
?macthId=222&time=10001 |
4.在app中如何使用
在AndroidManifest.xml中对activity标签增加intent-filter设置Schema
<activity android:name=".SecondActivity"><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="zymobi"android:host="3g2win"android:port="9999"android:path="/macthDetail"/></intent-filter></activity>
复制代码
注意:
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
复制代码
5.如何调用
1.在html中调用非常简单
<a href="zymobi://3g2win:9999/macthDetail?macthId=222&time=10001">打开源生应用指定的页面</a>
复制代码
2.在源生应用中调用也很简单
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("zymobi://3g2win:9999/macthDetail?macthId=222&time=10001"));
startActivity(intent);
复制代码
6.在源生界面获取uri和各个参数
Intent intent = getIntent();Uri data = intent.getData(); //String action = intent.getAction();String scheme = intent.getScheme();Set<String> categories = intent.getCategories();Log.e("TAG", "data==========="+data);Log.e("TAG", "action==========="+action);Log.e("TAG", "categories==========="+categories);Log.e("TAG", "DataString==========="+intent.getDataString());Log.e("TAG", "==============================");Log.e("TAG", "scheme==========="+scheme);Log.e("TAG", "id ==========="+data.getQueryParameterNames());Log.e("TAG", "host==========="+data.getHost());Log.e("TAG", "path==========="+data.getPath());Log.e("TAG", "port==========="+data.getPort());
复制代码
输出结果
4-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: data===========zymobi://3g2win:9999/macthDetail?goodsId=10011002&time=1111
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: action===========android.intent.action.VIEW
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: categories===========null
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: DataString===========zymobi://3g2win:9999/macthDetail?goodsId=10011002&time=1111
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: ==============================
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: scheme===========zymobi
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: id ===========[goodsId, time]
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: host===========3g2win
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: path===========/macthDetail
04-11 18:13:56.335 5198-5198/com.phone.myapplication E/TAG: port===========9999
复制代码
具体含义可以对比传入的参数
7. 判断Schema是否有效
判断Schema是否有效,也可以说判断应用是否安装(在确定要启动的应用已经配置了scheme)
app源生判断Sheme是否有效
Intent intent = newIntent(Intent.ACTION_VIEW, Uri.parse("zymobi://3g2win:9999/macthDetail?macthId=222&time=10001"));List<ResolveInfo> activities =packageManager.queryIntentActivities(intent, 0);
boolean isValid = !activities.isEmpty();
Toast.makeText(this,isValid+"",Toast.LENGTH_LONG).show();
最后
如果你觉得此文对你有一丁点帮助,点个赞。或者可以加入我的开发交流群:1025263163相互学习,我们会有专业的技术答疑解惑
如果你觉得这篇文章对你有点用的话,麻烦请给我们的开源项目点点star:http://github.crmeb.net/u/defu不胜感激 !
完整源码下载地址:https://market.cloud.tencent.com/products/33276
PHP学习手册:https://doc.crmeb.com
技术交流论坛:https://q.crmeb.com
关注私信回复 crmeb 获得任意产品思维导图原件
Android 中Scheme协议的使用详解相关推荐
- Android 中Scheme协议的使用详解唤起Activity或App
1. 什么是URL Scheme? 是一种页面内跳转协议:通过定义自己的scheme协议,可以非常方便跳转app中的各个页面. 2.什么时候使用 服务器下发跳转路径,客户端根据服务器下发跳转路径跳转相 ...
- Android 中 Scheme 协议的使用详解
什么是 URL Scheme? 简单的说就是 android 中的一种页面内跳转协议,方便 app 页面的内的跳转 2.什么时候使用 服务器下发跳转路径,客户端根据 服务器下发跳转路径跳转相应的页面 ...
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
本文原创, 转载请注明出处:http://blog.csdn.net/qinjuning 上篇文章<<Android中measure过程.WRAP_CONTENT详解以及xml布局文 ...
- android 中的悬浮按钮,Android 中FloatingActionButton(悬浮按钮)实例详解
android 中floatingactionbutton(悬浮按钮)实例详解 一.介绍 这个类是继承自imageview的,所以对于这个控件我们可以使用imageview的所有属性 二.使用准备, ...
- Android中联系人和通话记录详解(2)
在文章Android中联系人和通话记录详解(1)中对通话记录进行了分析,本章将对联系人的数据库表.字段以及Insert,Query,Delelte,Update四大基本数据操作进行分析. 与联系人相关 ...
- Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析
转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...
- Android中内存泄漏超级精炼详解
一.前期基础知识储备 (1)什么是内存? JAVA是在JVM所虚拟出的内存环境中运行的,JVM的内存可分为三个区:堆(heap).栈(stack)和方法区(method). 栈(stack):是简单的 ...
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
在之前一篇博文中<< Android中View绘制流程以及invalidate()等相关方法分析>> ,简单的阐述 了 Android View 绘制流程的三个步骤,即: 1. ...
- android中几种定位方式详解
目录 前言: 1.GPS定位 2.NETWORK定位 3.AGPS定位 4.基站定位 5.WIFI定位 6.混合定位 目前,移动端大致通过三种方式来进行设备定位:GPS.基站.wifi.本文就详细的讲 ...
最新文章
- NS安装问题收集(2)
- CentOS7.9关闭SELinux
- IE下var丢失造成的错误
- windows商店_Windows记事本应用现在可以从Microsoft Store中获得
- 使用Prometheus监控Cloudflare的全球网络
- 我的世界java版使用剑_我的世界:JAVA版藏“私货”内置绝世好剑与神功,你玩的版本有吗...
- Microsoft Project学习系列(一)
- 为informix数据库中的表创建同义词
- python中日志logging模块和异常捕获traceback模块的使用
- c语言寻找文件指令,c语言实现文件查找
- pcshare完美版
- 全栈式PHP集成环境-laragon(一)介绍、安装
- 利用Excel爬取网页数据
- 反思: Google 为何把 SurfaceView 设计的这么难用?
- python中 三元表达式
- TP4056 充电电路学习借鉴
- window10家庭版安装docker记录
- shell 编程三剑客之三:awk 详解
- surface和华为平板_微软的Surface Duo是手机和平板电脑的完美融合
- 【CF1626B】minor reduction
热门文章
- python魔法参数_python中的魔法参数:*args和**kwargs
- 【全网最全】Vue 组件之间的传值
- 【阿里招聘】三个与阿里初恋的故事
- ..\Output\CT117E-LCD.axf: Error: L6218E: Undefined symbol USART_SendData (referred from uart.o).
- Redis应用场景-分布式锁
- C# .NET winform地图开发GMap离线地图在线地图自建地图服务器
- NOIP2018-摆渡车
- set ff=unix linux报编码错误直接vi
- 金在中:心情不好的时候张根硕会陪我玩
- 中国芯片机会:突破封装技术,打通芯片生产最后一公里