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.ContentValues;
8 import android.content.Context;
9 import android.database.Cursor;
10 import android.net.Uri;
11 import android.provider.MediaStore;
14 * Utilities for testing operations on content URI.
16 public class ContentUriTestUtils {
18 * Insert an image into the MediaStore, and return the content URI. If the
19 * image already exists in the MediaStore, just retrieve the URI.
21 * @param context Application context.
22 * @param path Path to the image file.
23 * @return Content URI of the image.
26 private static String insertImageIntoMediaStore(Context context, String path) {
27 // Check whether the content URI exists.
28 Cursor c = context.getContentResolver().query(
29 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
30 new String[] { MediaStore.Video.VideoColumns._ID },
31 MediaStore.Images.Media.DATA + " LIKE ?",
32 new String[] { path },
34 if (c != null && c.getCount() > 0) {
37 return Uri.withAppendedPath(
38 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toString();
41 // Insert the content URI into MediaStore.
42 ContentValues values = new ContentValues();
43 values.put(MediaStore.MediaColumns.DATA, path);
44 Uri uri = context.getContentResolver().insert(
45 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
46 return uri.toString();