From: Reimar Döffinger Date: Sat, 30 Jan 2016 09:15:21 +0000 (+0100) Subject: Refine check for failed download manager query. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=4f0e2b9302b6c3921e444467bb295f0ed6db1b99 Refine check for failed download manager query. --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 1ace561..a1bc4df 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -27,6 +27,7 @@ Download failed: \n%s. + Could not query download manager.\nIs it disabled or missing? Unzipping dictionary: \n%s Unzipping failed: \n%s Installation finished: \n%s. diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index 4b1723f..dacc6d7 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -131,7 +131,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { final DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); final Cursor cursor = downloadManager.query(query); - if (!cursor.moveToFirst()) { + if (cursor == null || !cursor.moveToFirst()) { Log.e(LOG, "Couldn't find download."); return; } @@ -617,9 +617,11 @@ public class DictionaryManagerActivity extends ActionBarActivity { query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); final Cursor cursor = downloadManager.query(query); + // Due to a bug, cursor is null instead of empty when + // the download manager is disabled. if (cursor == null) { new AlertDialog.Builder(DictionaryManagerActivity.this).setTitle(getString(R.string.error)) - .setMessage(getString(R.string.downloadFailed, "Couldn't query Download Manager")) + .setMessage(getString(R.string.downloadFailed, R.string.downloadManagerQueryFailed)) .setNeutralButton("Close", null).show(); return; }