1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.base;
7 import android.content.ContentResolver;
8 import android.content.ContentValues;
9 import android.content.Context;
10 import android.database.Cursor;
11 import android.net.Uri;
12 import android.provider.MediaStore;
14 import org.chromium.base.CalledByNative;
17 * Utilities for testing operations on content URI.
19 public class ContentUriTestUtils {
21 * Insert an image into the MediaStore, and return the content URI. If the
22 * image already exists in the MediaStore, just retrieve the URI.
24 * @param context Application context.
25 * @param path Path to the image file.
26 * @return Content URI of the image.
29 private static String insertImageIntoMediaStore(Context context, String path) {
30 // Check whether the content URI exists.
31 Cursor c = context.getContentResolver().query(
32 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
33 new String[] { MediaStore.Video.VideoColumns._ID },
34 MediaStore.Images.Media.DATA + " LIKE ?",
35 new String[] { path },
37 if (c != null && c.getCount() > 0) {
40 return Uri.withAppendedPath(
41 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toString();
44 // Insert the content URI into MediaStore.
45 ContentValues values = new ContentValues();
46 values.put(MediaStore.MediaColumns.DATA, path);
47 Uri uri = context.getContentResolver().insert(
48 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
49 return uri.toString();