cleaned up code, prevented multiple app details screens popping up, fixed "no such app" toast after install
This commit is contained in:
parent
e827be1b5b
commit
efd4ebeadf
@ -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;
|
||||
}
|
||||
|
||||
|
@ -150,10 +150,21 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
||||
*/
|
||||
public static long getDownloadId(Intent intent) {
|
||||
if (intent != null) {
|
||||
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);
|
||||
} else {
|
||||
return -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user