diff options
| -rw-r--r-- | core/java/android/app/DownloadManager.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java index fd13174a6a39..b781ce50c4db 100644 --- a/core/java/android/app/DownloadManager.java +++ b/core/java/android/app/DownloadManager.java @@ -1112,12 +1112,17 @@ public class DownloadManager { * ready to execute it and connectivity is available. * * @param request the parameters specifying this download - * @return an ID for the download, unique across the system. This ID is used to make future - * calls related to this download. + * @return an ID for the download, unique across the system. This ID is used to make + * future calls related to this download. Returns -1 if the operation fails. */ public long enqueue(Request request) { ContentValues values = request.toContentValues(mPackageName); Uri downloadUri = mResolver.insert(Downloads.Impl.CONTENT_URI, values); + if (downloadUri == null) { + // If insert fails due to RemoteException, it would return a null uri. + return -1; + } + long id = Long.parseLong(downloadUri.getLastPathSegment()); return id; } |