Intent隐式跳转及参数传递
来源:互联网 发布:ubuntu hadoop安装教程 编辑:程序博客网 时间:2024/05/06 22:25
简单来说intent隐式跳转就是用action打开activity,server,broadcast。intent传递参数的方式有两种,一种是大家熟悉的extra,键值对的形式,直接传递参数;另一种就是uri的方式,String str = "content://com.android.test?username=merlin&password=123456"; Uri uri = Uri.parse(str); Intent intent = new Intent(Intent.ACTION_VIEW,uri); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent); intent构造方法里的两个参数一个action,一个uri 。还要设置category。好了这些跳转的工作做完了那么就好看看如何接受了。首先接受方要在manifest文件里设置过滤器,来判断是不是要发给我的intent。 <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="com.android.test" android:scheme="content" /> </intent-filter>我们来看一下这个过滤器 首先
action category就是之前说过的传递的时候设置的 host就是str里冒号双斜杠前边的那个内容,host呢就是就是scheme和?中间的那部分当然还有port和path,这里就不说了 android.developer.com里会有详细介绍。在activity里获取uri然后判断host和scheme是不是我们想要的然后获取username和password具体获取方法是 String username = uri.getQueryParameter("username");获取host直接可以调用 uri.getHost()方法。获取完成之后可以执行想要做的操作。
String str = "meixian://com.meixian.shopkeeper?action=login&phone=1234&from=meixian_crm";Uri uri = Uri.parse(str);Intent intent = new Intent(Intent.ACTION_VIEW,uri);intent.addCategory(Intent.CATEGORY_DEFAULT);startActivity(intent);
这是接收的源码
Uri uri = getIntent().getData();if (uri !=null ){ String host = uri.getHost(); String scheme = uri.getScheme(); String param = uri.getQueryParameter("action"); if ("login".equals(param)){ String phone = uri.getQueryParameter("phone"); String from = uri.getQueryParameter("from"); textView.setText(phone+from); startActivity(new Intent(this,MainActivity.class).putExtra("name",phone+from)); }}
1 0
- Intent隐式跳转及参数传递
- Intent跳转布局及传递数据
- Android,使用Intent或Bundle传递参数,跳转页面。
- Android,使用Intent或Bundle传递参数,跳转页面。
- 使用Intent或Bundle传递参数,跳转页面。
- Android,使用Intent或Bundle传递参数,跳转页面
- SilverLight页面跳转及参数传递
- html页面跳转及参数传递
- Intent隐式跳转
- Android使用Intent传递复杂参数及复杂参数列表
- Android使用Intent传递复杂参数及复杂参数列表
- Intent带参数跳转
- 通过Intent传递参数
- Activity 参数传递 Intent
- intent传递参数
- intent传递参数
- Android intent传递参数
- Intent传递URL参数
- pg_rman理解以及模拟过程
- c++学习笔记之复合类型(c++ primer plus)
- 对大学生学习Linux系统的七项实用建议
- 基于STM32F4 DSP库的FIR滤波器使用心得
- JAVA基本语法(二)
- Intent隐式跳转及参数传递
- CS0433: 类型同时存在于...
- 网易编程题(3)
- xampp下无法启动MYSQL服务器解决方案
- git 新添加一个项目
- 天津理工大学复试
- 一个简单的linux的测试修改模板
- bootstrap tooltip.js解析
- Java基础之泛型