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后发生了什么?下面是个人学习过程中的总结,供个人复 ...
随机推荐
- UNIX shell 学习笔记 一 : 几个shell的规则语法对比
1. 查看系统有哪些可用的shell cat /etc/shell 2. 每种shell都有一个特殊内置变量来存上一条命令的退出状态,例: C/TC shell $status % cp fx fy ...
- linux 系统调用exec()
系统调用execve()对当前进程进行替换,替换者为一个指定的程序,其参数包括文件名(filename).参数列表(argv)以及环境变量(envp).exec函数族当然不止一个,但它们大致相同,在 ...
- 在ubuntu上配置LAMP架构
1. 安装MySQL /* ubuntu默认进入系统是普通用户 所以在真实工作中,我们会得到root的授权. 所以我们需要用sudo做一切只有root才能完成的操作. */ [root@LAMP ~] ...
- linux下运行jmeter脚本
1. win下生成测试计划 2. 上传至linux下 3.运行测试计划 sh jmeter.sh -n -t second_login.jmx -l res.jtl 错误1: solution ...
- BNU - 49102
进化之地(Evoland) Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO for ...
- java程序中如何为一个while(true)循环计时,超过一定时间比如10个小时就退出循环?
public void execute(int hour){ long t1 = System.currentTimeMillis(); while(true){ long t2 = System.c ...
- lr_Vugen界面图
- Linux上安装MongoDB
使用本教程使用.rpm 软件包在红帽企业Linux或CentOS Linux版本6和7上安装MongoDB Community Edition . 平台支持 本安装指南仅支持64位系统.详细信息请参见 ...
- Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))
C. Birthday time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 欧拉图 欧拉回路 欧拉通路 Euler
欧拉图 本文链接:http://www.cnblogs.com/Ash-ly/p/5397702.html 定义: 欧拉回路:图G的一个回路,如果恰通过图G的每一条边,则该回路称为欧拉回路,具有欧拉回 ...