diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index 90d400a66..981e01411 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -365,21 +365,6 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A private String getAppIdFromIntent() { Intent i = getIntent(); if (!i.hasExtra(EXTRA_APPID)) { - if (i.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { - // we have been passed a DownloadManager download id, so get the app id for it - long downloadId = i.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); - return AsyncDownloader.getAppId(this, downloadId); - } - - if (i.hasExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)) { - // we have been passed a DownloadManager download id, so get the app id for it - long[] downloadIds = i.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); - if (downloadIds != null && downloadIds.length > 0) { - return AsyncDownloader.getAppId(this, downloadIds[0]); - } - } - - Log.e(TAG, "No application ID found in the intent!"); return null; } diff --git a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloader.java index 852406eae..f6e63735f 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloader.java @@ -150,10 +150,21 @@ public class AsyncDownloader extends AsyncDownloadWrapper { */ public static long getDownloadId(Intent intent) { if (intent != null) { - return intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); - } else { - return -1; + if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { + // we have been passed a DownloadManager download id, so get the app id for it + return intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); + } + + if (intent.hasExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS)) { + // we have been passed a DownloadManager download id, so get the app id for it + long[] downloadIds = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); + if (downloadIds != null && downloadIds.length > 0) { + return downloadIds[0]; + } + } } + + return -1; } /** diff --git a/F-Droid/src/org/fdroid/fdroid/receiver/DownloadManagerReceiver.java b/F-Droid/src/org/fdroid/fdroid/receiver/DownloadManagerReceiver.java index 6f08e2323..913d1c4df 100644 --- a/F-Droid/src/org/fdroid/fdroid/receiver/DownloadManagerReceiver.java +++ b/F-Droid/src/org/fdroid/fdroid/receiver/DownloadManagerReceiver.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import org.fdroid.fdroid.AppDetails; +import org.fdroid.fdroid.net.AsyncDownloader; /** * Receive notifications from the Android DownloadManager @@ -12,11 +13,16 @@ import org.fdroid.fdroid.AppDetails; public class DownloadManagerReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + // work out the app Id to send to the AppDetails Screen + long downloadId = AsyncDownloader.getDownloadId(intent); + String appId = AsyncDownloader.getAppId(context, downloadId); + // pass the download manager broadcast onto the AppDetails screen and let it handle it Intent appDetails = new Intent(context, AppDetails.class); - appDetails.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + appDetails.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); appDetails.setAction(intent.getAction()); appDetails.putExtras(intent.getExtras()); + appDetails.putExtra(AppDetails.EXTRA_APPID, appId); context.startActivity(appDetails); } }