summaryrefslogtreecommitdiff
path: root/core/java/android/app/DownloadManager.java
diff options
context:
space:
mode:
authorVasu Nori <vnori@google.com>2010-11-16 17:58:22 -0800
committerVasu Nori <vnori@google.com>2010-11-16 17:58:22 -0800
commit6e2b2a660ebc2f690b341da6e83d2cd2af99ebeb (patch)
tree4ddef437b5e355d4ecb1b88fbf297663ef74ca60 /core/java/android/app/DownloadManager.java
parenteb4e475d94565149fd782c2f6141854b5e8cffe9 (diff)
return file uri from downloadmanager instead of content uri for public downloads
also add another public method to return mimetype for the given downloaded file change is related to bug:3198355 Change-Id: I90bae443eec36968e0d533d9b07a514df369ac29
Diffstat (limited to 'core/java/android/app/DownloadManager.java')
-rw-r--r--core/java/android/app/DownloadManager.java44
1 files changed, 38 insertions, 6 deletions
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index 6e1853362f69..09a21f8ba0cd 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -886,8 +886,8 @@ public class DownloadManager {
* downloaded successfully. otherwise, null is returned.
*<p>
* If the specified downloaded file is in external storage (for example, /sdcard dir),
- * then it is assumed to be safe for anyone to read and the returned {@link Uri} can be used
- * by any app to access the downloaded file.
+ * then it is assumed to be safe for anyone to read and the returned {@link Uri} corresponds
+ * to the filepath on sdcard.
*
* @param id the id of the downloaded file.
* @return the {@link Uri} for the given downloaded file id, if download was successful. null
@@ -903,8 +903,7 @@ public class DownloadManager {
return null;
}
while (cursor.moveToFirst()) {
- int status = cursor.getInt(cursor.getColumnIndexOrThrow(
- DownloadManager.COLUMN_STATUS));
+ int status = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_STATUS));
if (DownloadManager.STATUS_SUCCESSFUL == status) {
int indx = cursor.getColumnIndexOrThrow(
Downloads.Impl.COLUMN_DESTINATION);
@@ -919,8 +918,9 @@ public class DownloadManager {
return ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, id);
} else {
// return public uri
- return ContentUris.withAppendedId(
- Downloads.Impl.PUBLICLY_ACCESSIBLE_DOWNLOADS_URI, id);
+ String path = cursor.getString(
+ cursor.getColumnIndexOrThrow(COLUMN_LOCAL_FILENAME));
+ return Uri.fromFile(new File(path));
}
}
}
@@ -934,6 +934,38 @@ public class DownloadManager {
}
/**
+ * Returns {@link Uri} for the given downloaded file id, if the file is
+ * downloaded successfully. otherwise, null is returned.
+ *<p>
+ * If the specified downloaded file is in external storage (for example, /sdcard dir),
+ * then it is assumed to be safe for anyone to read and the returned {@link Uri} corresponds
+ * to the filepath on sdcard.
+ *
+ * @param id the id of the downloaded file.
+ * @return the {@link Uri} for the given downloaded file id, if download was successful. null
+ * otherwise.
+ */
+ public String getMimeTypeForDownloadedFile(long id) {
+ Query query = new Query().setFilterById(id);
+ Cursor cursor = null;
+ try {
+ cursor = query(query);
+ if (cursor == null) {
+ return null;
+ }
+ while (cursor.moveToFirst()) {
+ return cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MEDIA_TYPE));
+ }
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ // downloaded file not found or its status is not 'successfully completed'
+ return null;
+ }
+
+ /**
* Restart the given downloads, which must have already completed (successfully or not). This
* method will only work when called from within the download manager's process.
* @param ids the IDs of the downloads