String myparent=newPath.substring(0, newPath.lastIndexOf("/")).substring(newPath.substring(0, newPath.lastIndexOf("/")).lastIndexOf("/")+1);
Uri mImageUri=MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
ContentResolver mContentResolver=getContentResolver();
String[] projection={ MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.DATA };//只查询jpeg的图片
Cursor mCursor =mContentResolver.query(mImageUri, projection,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME+ "=? and (" + MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?)",new String[]{myparent, "image/jpeg", "image/png"},null);if (mCursor == null) {
Toast.makeText(getBaseContext(),"请装入SD卡, 或者图库没有照片", Toast.LENGTH_SHORT).show();
}
myimages.clear();while(mCursor.moveToNext()) {//获取的图片的id
int id =mCursor.getInt(mCursor.getColumnIndex(MediaStore.Images.Media._ID));//图片所在当前目录id
int parentiD =mCursor.getInt(mCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID));//图片所在当前目录名称
String parentname =mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));//图片名称
String imagename =mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));//获取图片的路径
String path =mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
ImageInfo imageInfo=newImageInfo(id, imagename, path, parentiD, parentname);
imageInfo.setId(id);
imageInfo.setParentID(parentiD);
imageInfo.setParentName(parentname);
imageInfo.setImageName(imagename);
imageInfo.setPath(path);
myimages.add(imageInfo);
}
mCursor.close();