From 4f0e2b9302b6c3921e444467bb295f0ed6db1b99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 30 Jan 2016 10:15:21 +0100 Subject: [PATCH] Refine check for failed download manager query. --- res/values/strings.xml | 1 + .../android/dictionary/DictionaryManagerActivity.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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; } -- 2.43.0