1 settype

使用该函数表示要查找文件的mime类型(如*/*),这个和组件在manifest里定义的相对应,但在源代码里:

view plain copy to clipboard print ?
  1. public  Intent setData(Uri data) {  
  2.         mData = data;  
  3.         mType = null ;  
  4.         return   this ;  
  5.     }  

public Intent setData(Uri data) { mData = data; mType = null; return this; }

 

会将type设为null。

2 setdata

该函数的参数是uri,所以要将数据通过该函数传递时,记得要把数据转化为uri,如Uri.fromFile(new File("/mnt/sdcard/"))。

该函数源代码

view plain copy to clipboard print ?
  1. public  Intent setType(String type) {  
  2.         mData = null ;  
  3.         mType = type;  
  4.         return   this ;  
  5.     }  

public Intent setType(String type) { mData = null; mType = type; return this; }

 

3 所以要同时设置data和type的话只能用函数setdataandtype了

view plain copy to clipboard print ?
  1. public  Intent setDataAndType(Uri data, String type) {  
  2.         mData = data;  
  3.         mType = type;  
  4.         return   this ;  
  5.     }  

public Intent setDataAndType(Uri data, String type) { mData = data; mType = type; return this; }

 

目前还不是很明白Android这样做的原因,请高手指点指点,谢谢!

更多相关文章

  1. Android 图文数据JSON解析,金山词霸每日一句API的调用
  2. Android数据库SQLite使用详解一 : SQLiteOpenHelper详解
  3. android sqlite数据库封装 实现crud
  4. Android 与 JS 交互数据上限问题【Refusing to load URL as it e
  5. 在 Android 应用中使用数据库
  6. C基础—函数指针,联合体,枚举,结构体和结构体指针
  7. android 数据传输之JSON

随机推荐

  1. Looper
  2. Android样式和主题
  3. Android之自制的分页表格控件
  4. Android绘图机制与处理技巧——Android图
  5. Unity 与Android的交互(Android studio)
  6. [转] Android TextView处理HTML标签、显
  7. Android(安卓)Studio 0.6.1 中 gradle 构
  8. 博客开篇
  9. 如何使Android应用程序获得root权限
  10. android 3.3 butterknife-7.0.1。jar(com