Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.database.Cursor; import android.net.Uri; import android.provider.MediaStore; public class Main { public static int getImageIdFromPath(Activity activity, String filePath) { String[] projection = { MediaStore.Images.Media._ID }; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String where = String.format("_data like '%s' ", filePath); Cursor cursor = MediaStore.Images.Media.query(activity.getContentResolver(), uri, projection, where, null); int image_id = 0; if (cursor.getCount() != 0) { cursor.moveToFirst(); image_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); cursor.close(); } return image_id; } }