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

Unified Diff: base/android/java/src/org/chromium/base/FileUtils.java

Issue 2799533002: Use file Uri to launch intent for download on M and below (Closed)
Patch Set: nit 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 side-by-side diff with in-line comments
Download patch
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;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698