From c499ca930edfb540b7161567d59dd320f0360eb8 Mon Sep 17 00:00:00 2001 From: Filip Matusiak Date: Thu, 23 Aug 2012 15:05:05 +0200 Subject: Handle DownloadManager expceptions Handles illegal state exceptions thrown by DownloadManager on two ocassions: * the directory sdcard/Downloads is an ordinary file * could not create dirctory sdcard/Downloads Change will log an error, additionally toast with information will pop up. Change-Id: If853d3218a188bc77c187362a70697126b90989d --- src/com/android/browser/DownloadHandler.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/com/android/browser/DownloadHandler.java') diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java index dee10ae2e..208d4ce8c 100644 --- a/src/com/android/browser/DownloadHandler.java +++ b/src/com/android/browser/DownloadHandler.java @@ -195,8 +195,17 @@ public class DownloadHandler { request.setMimeType(mimetype); // set downloaded file destination to /sdcard/Download. // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype? - request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); - // let this downloaded file be scanned by MediaScanner - so that it can + try { + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); + } catch (IllegalStateException ex) { + // This only happens when directory Downloads can't be created or it isn't a directory + // this is most commonly due to temporary problems with sdcard so show appropriate string + Log.w(LOGTAG, "Exception trying to create Download dir:", ex); + Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, + Toast.LENGTH_SHORT).show(); + return; + } + // let this downloaded file be scanned by MediaScanner - so that it can // show up in Gallery app, for example. request.allowScanningByMediaScanner(); request.setDescription(webAddress.getHost()); -- cgit v1.2.3