内容提供者

一。权限

联网的权限:
写SD卡权限:
读SD卡权限:
读取联系人的权限:
读取短信的权限:
读取通话记录的权限:

二、URI

1.获取音频: (1)uri:MediaStore.Audio.Media.EXTERNAL_CONTENT_URI (2)字段:TITLE:歌名 ARTIST 歌手 DURATION 总时长 DATA 地址
String[] strs= new String[]{MediaStore.Audio.Media.TITLE,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media.DURATION,MediaStore.Audio.Media.DATA};
2.获取视频: (1)uri:MediaStore.Video.Media.EXTERNAL_CONTENT_URI (2)字段:TITLE:歌名 ARTIST 歌手 DURATION 总时长 DATA 地址
String[] strs= new String[]{MediaStore.Video.Media.TITLE,MediaStore.Video.Media.ARTIST,MediaStore.Video.Media.DURATION,MediaStore.Video.Media.DATA};
3.获取图库: (1)uri:MediaStore.Images.Media.EXTERNAL_CONTENT_URI (2)字段:
MediaStore.Images.Media.TITLE;图片名称
MediaStore.Images.Media.SIZE;大小
MediaStore.Images.Media.DATA;地址
4.获取联系人: (1)uri:ContactsContract.CommonDataKinds.Phone.CONTENT_URI (2)字段:Phone.DISPLAY_NAME:姓名 NUMBER:电话 String[] strs= new
String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER};
5.获取短信: (1)uriTelephony.Sms.CONTENT_URI (2)字段:ADDRESS 地址 BODY 内容 String[] strs= new
String[]{Telephony.Sms.ADDRESS,Telephony.Sms.BODY};
备注:1 2 3 读sd卡的权限 4 读联系人的权限 5 读短信的权限
6.通话记录:
(1)uri:CallLog.Calls.CONTENT_URI
(2)字段:
NUMBER:电话号码
DATE:时间 毫秒
DURATION:总时长 秒
TYPE 类型

三、视频、音频、图片、联系人
1.获取视频
ContentResolver contentResolver = getContentResolver();
Uri uri= MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
while(cursor.moveToNext()){
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.TITLE));
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
Video video = new Video(title, data);
list.add(video);
}

2.获取图片
ContentResolver contentResolver = getContentResolver();
Uri externalContentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor query1 = contentResolver.query(externalContentUri, null, null, null,null);
while (query1.moveToNext()) {
String string = query1.getString(query1.getColumnIndex(MediaStore.Images.Media.TITLE));
long aLong = query1.getLong(query1.getColumnIndex(MediaStore.Images.Media.SIZE));
String data = query1.getString(query1.getColumnIndex(MediaStore.Images.Media.DATA));
tu tu = new tu(data);
total.add(tu);
}

3.获取音频
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
while (cursor.moveToNext()) {
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.SIZE));
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
Toast.makeText(MainActivity.this, “音频”+title+":"+size+":"+data, Toast.LENGTH_SHORT).show();
}

4.获取联系人
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor query = contentResolver.query(uri, null, null, null, null);
while (query.moveToNext()){
String name = query.getString(query.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = query.getString(query.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(MainActivity.this, " “+name+” "+number, Toast.LENGTH_SHORT).show();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值