Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java

Issue 2801033002: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.base; 5 package org.chromium.base;
6 6
7 import android.content.ContentValues; 7 import android.content.ContentValues;
8 import android.content.Context;
8 import android.database.Cursor; 9 import android.database.Cursor;
9 import android.net.Uri; 10 import android.net.Uri;
10 import android.provider.MediaStore; 11 import android.provider.MediaStore;
11 12
12 import org.chromium.base.annotations.CalledByNative; 13 import org.chromium.base.annotations.CalledByNative;
13 14
14 /** 15 /**
15 * Utilities for testing operations on content URI. 16 * Utilities for testing operations on content URI.
16 */ 17 */
17 public class ContentUriTestUtils { 18 public class ContentUriTestUtils {
18 /** 19 /**
19 * Insert an image into the MediaStore, and return the content URI. If the 20 * Insert an image into the MediaStore, and return the content URI. If the
20 * image already exists in the MediaStore, just retrieve the URI. 21 * image already exists in the MediaStore, just retrieve the URI.
21 * 22 *
23 * @param context Application context.
22 * @param path Path to the image file. 24 * @param path Path to the image file.
23 * @return Content URI of the image. 25 * @return Content URI of the image.
24 */ 26 */
25 @CalledByNative 27 @CalledByNative
26 private static String insertImageIntoMediaStore(String path) { 28 private static String insertImageIntoMediaStore(Context context, String path ) {
27 // Check whether the content URI exists. 29 // Check whether the content URI exists.
28 Cursor c = ContextUtils.getApplicationContext().getContentResolver().que ry( 30 Cursor c = context.getContentResolver().query(
29 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 31 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
30 new String[] {MediaStore.Video.VideoColumns._ID}, 32 new String[] { MediaStore.Video.VideoColumns._ID },
31 MediaStore.Images.Media.DATA + " LIKE ?", new String[] {path}, n ull); 33 MediaStore.Images.Media.DATA + " LIKE ?",
34 new String[] { path },
35 null);
32 if (c != null && c.getCount() > 0) { 36 if (c != null && c.getCount() > 0) {
33 c.moveToFirst(); 37 c.moveToFirst();
34 int id = c.getInt(0); 38 int id = c.getInt(0);
35 return Uri.withAppendedPath( 39 return Uri.withAppendedPath(
36 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toStr ing(); 40 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id).toStr ing();
37 } 41 }
38 42
39 // Insert the content URI into MediaStore. 43 // Insert the content URI into MediaStore.
40 ContentValues values = new ContentValues(); 44 ContentValues values = new ContentValues();
41 values.put(MediaStore.MediaColumns.DATA, path); 45 values.put(MediaStore.MediaColumns.DATA, path);
42 Uri uri = ContextUtils.getApplicationContext().getContentResolver().inse rt( 46 Uri uri = context.getContentResolver().insert(
43 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 47 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
44 return uri.toString(); 48 return uri.toString();
45 } 49 }
46 } 50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698