获取系统数据库中图片和视屏资源

获取图片信息

public void doPic(){
	if(Environment.getExternalStorageState().equals(Environment.MEDIA_UNMOUNTED)){
		Toast.makeText(this, "暂无外部存储", Toast.LENGTH_LONG).show();
		return ;
	}
	Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
	ContentResolver mResolver = this.getContentResolver();
	
	//查询图片,如果需要查询更多的图片类型,可以设置更多的MIME_TYPE
	Cursor mCursor = mResolver.query(mImageUri, null,MediaStore.Images.Media.MIME_TYPE+"=? or " + 
			MediaStore.Images.Media.MIME_TYPE+"=?", 
			new String[]{"image/jpeg","image/png"}, MediaStore.Images.Media.DATE_MODIFIED);
	Log.e("TAG", mCursor.getCount() + "");
		
	while (mCursor.moveToNext()) {
		int columnCount = mCursor.getColumnCount();
		String[] columnNames = mCursor.getColumnNames();
		for(String columnName : columnNames){
			LOGALL(mCursor, columnName);
			//获取文件路径
			String path = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media._ID));
		}
	}
}
private void LOGALL(Cursor mCursor, String columnName) {
	String string = mCursor.getString(mCursor.getColumnIndex(columnName));
	Log.e("TAG", "columnName:" + columnName +" = " + string);
}


获取视屏

public void doVedio(){
		if(Environment.getExternalStorageState().equals(Environment.MEDIA_UNMOUNTED)){
			Toast.makeText(this, "暂无外部存储", Toast.LENGTH_LONG).show();
			return ;
		}
		
		Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
		ContentResolver mResolver = getContentResolver();
		//Cursor mCursor = mResolver.query(uri, null, MediaStore.Video.Media.MIME_TYPE + "= ?", new String[]{"vedio/mp4"}, MediaStore.Video.Media.DATE_MODIFIED);
		Cursor mCursor = mResolver.query(uri, null, null, null, MediaStore.Video.Media.DATE_MODIFIED);
		Log.e("TAG", mCursor.getCount() + "");
		
		while (mCursor.moveToNext()) {
			int columnCount = mCursor.getColumnCount();
			String[] columnNames = mCursor.getColumnNames();
			for(String columnName : columnNames){
				LOGALL(mCursor, columnName);
				//获取文件路径
			}
			String path = mCursor.getString(mCursor.getColumnIndex(MediaStore.Video.Media.DATA));
			Log.e("TAG", "path:" + path);
		}
	}



 

你可能感兴趣的:(获取系统数据库中图片和视屏资源)