Android 通过URL scheme 实现点击浏览器中的URL链接,启动特定的App,并调转页面传递参数
点击浏览器中的URL链接,启动特定的App。
- 首先做成HTML的页面,页面内容格式如下:
<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a>
这一句就可以了。
各个项目含义如下所示:
scheme:判别启动的App。 ※详细后述
host:适当记述
path:传值时必须的key ※没有也可以
query:获取值的Key和Value ※没有也可以
- 作为测试好好写了一下,如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<br/>
<a href="fyfeng://Panda/test1?name=http://124.200.36.22:8000/test/namelist.json&age=26">打开app</a><br/>
<br/>
<a href="fyfeng://Panda/test2?name=zhangsan&age=27">打开app1</a><br/>
<br/>
<a href="fyfeng://Panda/test3?name=zhangsan&age=28">打开app2</a><br/>
<br/>
</body>
</html>
- 接下来是Android端。
首先在AndroidManifest.xml的MAIN Activity下追加以下内容。(启动Activity时给予)
※必须添加项
<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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>
</intent-filter>
HTML记述的内容加入
<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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>
</intent-filter>
可以复制代码,这样的话,没有问题。
- 接下来在Activity中需要取值的地方添加以下代码,我是直接写在OnCreate函数里的:
Intent i_getvalue = getIntent();
String action = i_getvalue.getAction();
if(Intent.ACTION_VIEW.equals(action)){
Uri uri = i_getvalue.getData();
if(uri != null){
String name = uri.getQueryParameter("name");
String age= uri.getQueryParameter("age");
}
}
这样就能获取到URL传递过来的值了。
我在测试的超链接上添加name的属性是一个需要请求服务器的URL,这样的话,我们可以通过根据这个URL请求服务器,获取到一些我们所需要的数据,这个数据的是以Json的形式存在,通过volley请求下来数据,并使用Gson解析后得到数据。
public static void getUrlValue(Intent i_getvalue, final String tag, Context context) {
String action = i_getvalue.getAction();
if (Intent.ACTION_VIEW.equals(action)) {
Uri uri = i_getvalue.getData();
if (uri != null) {
mRequestQueue = Volley.newRequestQueue(context);
final String name = uri.getQueryParameter("name");
// System.out.print(name);
// final String name = "http://124.200.36.22:8000/test/namelist.json";
String age = uri.getQueryParameter("age");
String host = uri.getHost();
String dataString = i_getvalue.getDataString();
String id = uri.getQueryParameter("id");
String path = uri.getPath();
String path1 = uri.getEncodedPath();
String queryString = uri.getQuery();
new Thread(new Runnable() {
@Override
public void run() {
if (name != null) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(name.toString().trim(), null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Gson gson = new Gson();
Singersin=gson.fromJson(response.toString(),Singer.class);
daytime= sin.getSinger().getDaytime(); order=sin.getSinger().getOrder(); title=sin.getSinger().getTitle();
Log.d("TAG", response.toString());
Log.i(tag, "name:" + name);
Log.i(tag, "time:" + daytime);
Log.i(tag, "order:" + order);
Log.i(tag, "title:" + title);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("TAG", error.getMessage(), error);
}
}); mRequestQueue.add(jsonObjectRequest);
}
}
}).start();
Log.i(tag, "dataString:" + dataString);
Log.i(tag, "id:" + id);
Log.i(tag, "path:" + path);
Log.i(tag, "path1:" + path1);
Log.i(tag, "queryString:" + queryString);
Log.i(tag, "name" + name + " age" + age);
}
}
}
}
服务器的Json数据
{'singer':{'daytime':12,'order':'45','title':'订单'}}
日志输出结果:
D/TAG: {"singer":{"daytime":12,"order":"45","title":"订单"}}
name:http://124.200.36.22:8000/test/namelist.json
time:12
order:45
title:订单
path:/test1
path:/test2
demo链接点击去下载
http://download.csdn.net/detail/jackron2014/9483691
Android 通过URL scheme 实现点击浏览器中的URL链接,启动特定的App,并调转页面传递参数的更多相关文章
- 在浏览器中输入URL并回车后都发生了什么?
1.解析URL ________________________________________________________________________ 关于URL: URL(Universa ...
- 在浏览器中输入URL按下回车键后发生了什么
在浏览器中输入URL按下回车键后发生了什么 [1]解析URL[2]DNS查询,解析域名,将域名解析为IP地址[3]ARP广播,根据IP地址来解析MAC地址[4]分别从应用层到传输层.网络层和数据链路层 ...
- 深入浅出经典面试题:从浏览器中输入URL到页面加载发生了什么 - Part 3
备注: 因为文章太长,所以将它分为三部分,本文是第三部分. 第一部分:深入浅出经典面试题:从浏览器中输入URL到页面加载发生了什么 - Part 1 第二部分:深入浅出经典面试题:从浏览器中输入URL ...
- 浏览器中输入URL发生了什么
浏览器中输入URL会发生什么呢?这是我们经常会问到的一个问题. 我们知道的都是会发送http请求,服务端会处理请求给我们响应的结果,浏览器会渲染html 页面 但其实会遗漏掉一些比较重要的东西.下面的 ...
- 从浏览器中输入URL到页面加载的发生了什么-转载
转:https://www.cnblogs.com/confach/p/10050013.html 背景 “从浏览器中输入URL到页面加载的发生了什么“,这是一道经典的面试题,涉及到的知识面非常多,但 ...
- 在浏览器中输入url回车之后会发生什么
在浏览器中输入URL之后,浏览器会经历以下5个步骤: 1.解析URL 2.DNS域名解析 3.浏览器与网站建立TCP链接(三次握手) 4.请求和传输数据 5.浏览器渲染页面 一.解析URL 什么是ur ...
- 【ASP.NET Core】EF Core - “影子属性” 深入浅出经典面试题:从浏览器中输入URL到页面加载发生了什么 - Part 1
[ASP.NET Core]EF Core - “影子属性” 有朋友说老周近来博客更新较慢,确实有些慢,因为有些 bug 要研究,另外就是老周把部分内容转到直播上面,所以写博客的内容减少了一点. ...
- 在浏览器中输入url地址 -> 显示主页的过程
-来自<图解HTTP> 最近在进行前端面试方面的一些准备,看了网上许多相关的文章,发现有一个问题始终绕不开: 在浏览器中输入URL到整个页面显示在用户面前时这个过程中到底发生了什么.仔细思 ...
- 【转】浏览器中输入url后发生了什么
原文地址:http://www.jianshu.com/p/c1dfc6caa520 在学习前端的过程中经常看到这样一个问题:当你在浏览器中输入url后发生了什么?下面是个人学习过程中的总结,供个人复 ...
随机推荐
- java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast
严重: Exception starting filter encodingFilterjava.lang.ClassCastException: org.springframework.web.fi ...
- django渲染模板时跟vue使用的{{ }}冲突解决方法
var vm = new Vue({ el: '#app', // 分割符: 修改vue中显示数据的语法, 防止与django冲突 delimiters: ['[[', ']]'], data: { ...
- 基于rest_framework和redis实现购物车的操作,结算,支付
前奏: 首先,要在主机中安装redis,windows中安装,下载一个镜像,直接进行下一步的安装,安装成功后,在cmd中输入redis-cli 安装python的依赖库: redis 和 ...
- Set Matrix Zeroes——常数空间内完成
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Did yo ...
- Laravel通过Swoole提升性能
1.安装配置laravel 1.1.composer下载laravel composer create-project --prefer-dist laravel/laravel blog " ...
- 使用kubeadm安装k8s集群故障处理三则
最近在作安装k8s集群,测试了几种方法,最终觉得用kubeadm应该最规范. 限于公司特别的网络情况,其安装比网上不能访问google的情况还要艰难. 慢慢积累经验吧. 今天遇到的三则故障记下来作参考 ...
- 使用css做图标
首先原理是: 请一步一步粘贴代码,慢慢品味.其实,很简单... 1.首先三角形的前身是一个普通的矩形-正方形||长方形?ok! <div class='box'></div> ...
- 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) 日常训练
A - Archery Tournament 题目大意:按时间顺序出现靶子和射击一个位置,靶子的圆心为(x, y)半径为r,即圆与x轴相切,靶子不会重叠,靶子被击中后消失, 每次射击找出哪个靶子被射中 ...
- 如何开启apache的PHP-FPM实例
PHP-FPM 作为 FastCGI 进程管理器而广为熟知,它是PHPFastCGI 实现的改进,带有更为有用的功能,用于处理高负载的服务器和网站.下面列出其中一些功能: 新功能 拥有具有优雅(gra ...
- 7.spark Streaming 技术内幕 : 从DSteam到RDD全过程解析
原创文章,转载请注明:转载自 听风居士博客(http://www.cnblogs.com/zhouyf/) 上篇博客讨论了Spark Streaming 程序动态生成Job的过程,并留下一个疑问: ...