File image_file = new File(path); final Uri image_uri = Uri.fromFile(image_file); private static Uri fileUri2contentUri(Context context, Uri srcUri) { Uri uri = null; Uri baseUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] proj = { BaseColumns._ID }; String sel = MediaStore.Images.ImageColumns.DATA + " LIKE ?"; String[] selArgs = new String[] { srcUri.getPath() }; ContentResolver cr = context.getContentResolver(); try { Cursor cur = cr.query(baseUri, proj, sel, selArgs, null); cur.moveToFirst(); int cidx = cur.getColumnIndex(proj[0]); long id = cur.getLong(cidx); cur.close(); uri = Uri.parse(baseUri.toString() + "/" + id); } catch (Exception e) { Log.v("fileUri2contentUri", "file://からcontent://形式変換中にエラー", e); } return uri; }
コメントを残す