Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
| diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
| index 05186ebc77fc76b1e6f110d6777b1f1301508844..20e92d210968a847109205ff1f12b1a3ad7e2145 100644 |
| --- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
| +++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java |
| @@ -8,12 +8,13 @@ import android.annotation.TargetApi; |
| import android.app.Activity; |
| import android.content.ClipData; |
| import android.content.ContentResolver; |
| +import android.content.Context; |
| import android.content.Intent; |
| import android.net.Uri; |
| import android.os.AsyncTask; |
| import android.os.Build; |
| -import android.os.Environment; |
| import android.provider.MediaStore; |
| +import android.support.v4.content.FileProvider; |
| import android.text.TextUtils; |
| import org.chromium.base.CalledByNative; |
| @@ -40,6 +41,8 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{ |
| private static final String ALL_AUDIO_TYPES = AUDIO_TYPE + "*"; |
| private static final String ANY_TYPES = "*/*"; |
| private static final String CAPTURE_IMAGE_DIRECTORY = "browser-photos"; |
| + private static final String API_AUTHORITY_SUFFIX = ".FileProvider"; |
| + private static final String IMAGE_FILE_PATH = "images"; |
|
Ted C
2014/08/21 00:54:51
can this not be read from the xml file?
qinmin
2014/08/21 17:45:44
the <file-path> will not generate a resource id in
|
| private final long mNativeSelectFileDialog; |
| private List<String> mFileTypes; |
| @@ -66,8 +69,14 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{ |
| Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
| Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| - mCameraOutputUri = Uri.fromFile(getFileForImageCapture()); |
| + camera.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION + |
|
Ted C
2014/08/21 00:54:51
although these are 1 & 2 as values, it seems like
qinmin
2014/08/21 17:45:44
Done.
|
| + Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| + Context context = window.getApplicationContext(); |
| + mCameraOutputUri = FileProvider.getUriForFile(context, |
| + context.getPackageName() + API_AUTHORITY_SUFFIX, getFileForImageCapture(context)); |
| camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri); |
| + camera.setClipData( |
| + ClipData.newUri(context.getContentResolver(), "images", mCameraOutputUri)); |
|
Ted C
2014/08/21 00:54:51
and should this "images" be a reference to the con
qinmin
2014/08/21 17:45:44
This value doesn't seem to impact anything. In the
|
| Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| Intent soundRecorder = new Intent( |
| MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| @@ -125,18 +134,16 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{ |
| } |
| /** |
| - * Get a file for the image capture in the CAPTURE_IMAGE_DIRECTORY directory. |
| + * Get a file for the image capture in the IMAGE_FILE_PATH directory. |
| + * @param context The application context. |
| */ |
| - private File getFileForImageCapture() { |
| - File externalDataDir = Environment.getExternalStoragePublicDirectory( |
| - Environment.DIRECTORY_DCIM); |
| - File cameraDataDir = new File(externalDataDir.getAbsolutePath() + |
| - File.separator + CAPTURE_IMAGE_DIRECTORY); |
| - if (!cameraDataDir.exists() && !cameraDataDir.mkdirs()) { |
| - cameraDataDir = externalDataDir; |
| + private File getFileForImageCapture(Context context) { |
| + final File path = new File(context.getFilesDir(), IMAGE_FILE_PATH); |
| + if (!path.exists()) { |
| + path.mkdir(); |
| } |
| - File photoFile = new File(cameraDataDir.getAbsolutePath() + |
| - File.separator + System.currentTimeMillis() + ".jpg"); |
| + File photoFile = new File(path + File.separator + System.currentTimeMillis() + |
| + ".jpg"); |
| return photoFile; |
| } |
| @@ -160,7 +167,8 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{ |
| if (results == null) { |
| // If we have a successful return but no data, then assume this is the camera returning |
| // the photo that we requested. |
| - nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath(), ""); |
| + nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.toString(), |
| + mCameraOutputUri.getLastPathSegment()); |
| // Broadcast to the media scanner that there's a new photo on the device so it will |
| // show up right away in the gallery (rather than waiting until the next time the media |