Android examples for android.media:Media File
Gets a Uri that represents a media item with the specified filename.
import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import android.provider.BaseColumns; import android.provider.MediaStore; import android.provider.MediaStore; import java.util.ArrayList; import java.util.List; public class Main{ public static Uri uriForMediaWithFilename(ContentResolver resolver, String filename) {/*w w w .j a v a 2s . c o m*/ final String[] columns = { BaseColumns._ID, MediaColumns.DATA }; final String selection = MediaColumns.DATA + " LIKE ?"; final String[] selectionArgs = { "%" + filename }; Cursor cursor = resolver.query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, selection, selectionArgs, null); Uri uri = null; if (cursor.moveToFirst()) { String id = cursor.getString(0); uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon() .appendPath(id).build(); } cursor.close(); return uri; } }