Android下intent的setdata、settype和setdataandtype函数
16lz
2022-05-17
1 settype
使用该函数表示要查找文件的mime类型(如*/*),这个和组件在manifest里定义的相对应,但在源代码里:
view plain copy to clipboard print ?- public Intent setData(Uri data) {
- mData = data;
- mType = null ;
- return this ;
- }
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 ?- public Intent setType(String type) {
- mData = null ;
- mType = type;
- return this ;
- }
public Intent setType(String type) { mData = null; mType = type; return this; }
3 所以要同时设置data和type的话只能用函数setdataandtype了
view plain copy to clipboard print ?- public Intent setDataAndType(Uri data, String type) {
- mData = data;
- mType = type;
- return this ;
- }
public Intent setDataAndType(Uri data, String type) { mData = data; mType = type; return this; }
目前还不是很明白Android这样做的原因,请高手指点指点,谢谢!
更多相关文章
- Android下setLatestEventInfo警告、Handler警告、SimpleDateForm
- Notification用法,注意API版本,API大于11的setLatestEventInfo()方
- android源代码编译
- Android(安卓)studio 点击按钮跳转到新的Activity
- 设备驱动-----Android关机流程总结
- 基于ffmpeg的Android播放器开源代码
- C基础—函数指针,联合体,枚举,结构体和结构体指针
- Android(安卓)MediaPlayer 分析- MediaPlayerService.cpp
- 箭头函数的基础使用