| Index: base/android/java/src/org/chromium/base/FileUtils.java
|
| diff --git a/base/android/java/src/org/chromium/base/FileUtils.java b/base/android/java/src/org/chromium/base/FileUtils.java
|
| index 2ad70dd9a1c8ff65af68ba23cf4a6c86b8062364..931b0c4ace2cb8c99fcb01dbb6a850cd20c9fdd7 100644
|
| --- a/base/android/java/src/org/chromium/base/FileUtils.java
|
| +++ b/base/android/java/src/org/chromium/base/FileUtils.java
|
| @@ -5,6 +5,7 @@
|
| package org.chromium.base;
|
|
|
| import android.content.Context;
|
| +import android.net.Uri;
|
|
|
| import java.io.BufferedOutputStream;
|
| import java.io.File;
|
| @@ -86,4 +87,27 @@ public class FileUtils {
|
| }
|
| return false;
|
| }
|
| +
|
| + /**
|
| + * Returns a URI that points at the file.
|
| + * @param file File to get a URI for.
|
| + * @return URI that points at that file, either as a content:// URI or a file:// URI.
|
| + */
|
| + public static Uri getUriForFile(File file) {
|
| + // TODO(crbug/709584): Uncomment this when http://crbug.com/709584 has been fixed.
|
| + // assert !ThreadUtils.runningOnUiThread();
|
| + Uri uri = null;
|
| +
|
| + try {
|
| + // Try to obtain a content:// URI, which is preferred to a file:// URI so that
|
| + // receiving apps don't attempt to determine the file's mime type (which often fails).
|
| + uri = ContentUriUtils.getContentUriFromFile(file);
|
| + } catch (IllegalArgumentException e) {
|
| + Log.e(TAG, "Could not create content uri: " + e);
|
| + }
|
| +
|
| + if (uri == null) uri = Uri.fromFile(file);
|
| +
|
| + return uri;
|
| + }
|
| }
|
|
|