android4.0从文件管理器进入图库不能选择上一个和下一个图片
//: add by duanyf 20121105 start
int index = 0;
String str_index = null;
int pic_index = 0;
String type = Utils.ensureNotNull(intent.getType());
Log.d(TAG, "uri is " + uri);
if (uri.getScheme().equals("file") && (type.contains("image/"))) {
String path = uri.getEncodedPath();
if (path != null) {
path = Uri.decode(path);
ContentResolver cr = this.getContentResolver();
StringBuffer buff = new StringBuffer();
buff.append("(")
.append(Images.ImageColumns.DATA)
.append("=")
.append("'" + path + "'")
.append(")");
Cursor cur = cr.query(
Images.Media.EXTERNAL_CONTENT_URI,
new String[] { Images.ImageColumns._ID },
buff.toString(), null, null);
for (cur.moveToFirst(); !cur.isAfterLast(); cur
.moveToNext()) {
index = cur.getColumnIndex(Images.ImageColumns._ID);
// set _id value
index = cur.getInt(index);
}
if (index == 0) {
//do nothing
} else {
Uri uri_temp = Uri
.parse("content://media/external/images/media/"
+ index);
Log.d(TAG, "uri_temp is " + uri_temp);
if (uri_temp != null) {
uri = uri_temp;
}
}
Integer integer = new Integer(index);
str_index = integer.toString();
}
}
//: add by duanyf 20121105 end
Path itemPath = dm.findPathByUri(uri);
if(itemPath==null){
Log.w(TAG, "itemPath is null");
return;
}
Path albumPath = dm.getDefaultSetOf(itemPath);
//: add by duanyf 20121105 start
MediaSet mMediaSet = dm.getMediaSet(albumPath.toString());
if (mMediaSet != null) {
Log.d(TAG, "test :" + mMediaSet.getMediaItemCount());
int count = mMediaSet.getMediaItemCount();
ArrayList<MediaItem> mediaitemlist = mMediaSet.getMediaItem(0, count);
if (mediaitemlist == null)
{
mMediaSet.reload();
}
mediaitemlist = mMediaSet.getMediaItem(0, count);
Log.d(TAG, "str_index is " + str_index);
if (mediaitemlist != null){
for (int i=0; i<count; i++){
MediaItem item = mediaitemlist.get(i);
String path = item.getPath().toString();
Log.d(TAG, "path is " + path);
if (path.contains(str_index)){
break;
}
pic_index++;
}
if (pic_index<count && pic_index>=0){
data.putInt(PhotoPage.KEY_INDEX_HINT, pic_index);
}
} else {
Log.d(TAG, "mediaitemlist is null");
}
} else {
Log.d(TAG, "mMediaSet is null");
}
//: add by duanyf 20121105 end
不仅要图片能上一张下一张,下面的缩略图位置也得对应起来。