Example usage for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE

List of usage examples for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE

Introduction

In this page you can find the example usage for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE.

Prototype

String ACTION_DOWNLOAD_COMPLETE

To view the source code for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE.

Click Source Link

Document

Broadcast intent action sent by the download manager when a download completes.

Usage

From source file:it.rignanese.leo.slimfacebook.PictureActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture);

    savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // setup the sharedPreferences
    downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

    BroadcastReceiver receiver = downloadCompletedReceiver;
    registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

    SetupPictureWebView();//from   ww  w .j a v a  2s  . c om

    String pictureUrl = getIntent().getStringExtra("URL");
    webViewPicture.loadUrl(pictureUrl);
}

From source file:com.tenmiles.helpstack.service.AttachmentDownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    String package_name = intent.getPackage();
    String cpackage = context.getPackageName();

    if (package_name.equals(cpackage) && DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
        downloadCompleted(context, intent);
    } else if (package_name.equals(cpackage) && DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) {
        notificationClicked(context, intent);
    }/*from  w w w  . j  a  va2 s  . c o  m*/
}

From source file:com.commonsware.android.downmgr.DownloadFragment.java

@Override
public void onResume() {
    super.onResume();

    IntentFilter f = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);

    f.addAction(DownloadManager.ACTION_NOTIFICATION_CLICKED);

    getActivity().registerReceiver(onEvent, f);
}

From source file:com.ota.updates.receivers.AppReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();/*from   www .  j a  v a  2 s  .c  o m*/
    long mRomDownloadID = Preferences.getDownloadID(context);

    if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        long id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
        boolean isAddonDownload = false;
        int keyForAddonDownload = 0;

        Set<Integer> set = OtaUpdates.getAddonDownloadKeySet();
        Iterator<Integer> iterator = set.iterator();

        while (iterator.hasNext() && isAddonDownload != true) {
            int nextValue = iterator.next();
            if (id == OtaUpdates.getAddonDownload(nextValue)) {
                isAddonDownload = true;
                keyForAddonDownload = nextValue;
                if (DEBUGGING) {
                    Log.d(TAG, "Checking ID " + nextValue);
                }
            }
        }

        if (isAddonDownload) {
            DownloadManager downloadManager = (DownloadManager) context
                    .getSystemService(Context.DOWNLOAD_SERVICE);
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(id);
            Cursor cursor = downloadManager.query(query);

            // it shouldn't be empty, but just in case
            if (!cursor.moveToFirst()) {
                if (DEBUGGING)
                    Log.e(TAG, "Addon Download Empty row");
                return;
            }

            int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) {
                if (DEBUGGING)
                    Log.w(TAG, "Download Failed");
                Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload);
                OtaUpdates.removeAddonDownload(keyForAddonDownload);
                AddonActivity.AddonsArrayAdapter.updateProgress(keyForAddonDownload, 0, true);
                AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, false);
                return;
            } else {
                if (DEBUGGING)
                    Log.v(TAG, "Download Succeeded");
                Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload);
                OtaUpdates.removeAddonDownload(keyForAddonDownload);
                AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, true);
                return;
            }
        } else {
            if (DEBUGGING)
                Log.v(TAG, "Receiving " + mRomDownloadID);

            if (id != mRomDownloadID) {
                if (DEBUGGING)
                    Log.v(TAG, "Ignoring unrelated non-ROM download " + id);
                return;
            }

            DownloadManager downloadManager = (DownloadManager) context
                    .getSystemService(Context.DOWNLOAD_SERVICE);
            DownloadManager.Query query = new DownloadManager.Query();
            query.setFilterById(id);
            Cursor cursor = downloadManager.query(query);

            // it shouldn't be empty, but just in case
            if (!cursor.moveToFirst()) {
                if (DEBUGGING)
                    Log.e(TAG, "Rom download Empty row");
                return;
            }

            int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
            if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) {
                if (DEBUGGING)
                    Log.w(TAG, "Download Failed");
                Preferences.setDownloadFinished(context, false);
                if (Utils.isLollipop()) {
                    AvailableActivity.setupMenuToolbar(context); // Reset options menu
                } else {
                    AvailableActivity.invalidateMenu();
                }
                return;
            } else {
                if (DEBUGGING)
                    Log.v(TAG, "Download Succeeded");
                Preferences.setDownloadFinished(context, true);
                AvailableActivity.setupProgress(context);
                if (Utils.isLollipop()) {
                    AvailableActivity.setupMenuToolbar(context); // Reset options menu
                } else {
                    AvailableActivity.invalidateMenu();
                }
                return;
            }
        }
    }

    if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {

        long[] ids = extras.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);

        for (long id : ids) {
            if (id != mRomDownloadID) {
                if (DEBUGGING)
                    Log.v(TAG, "mDownloadID is " + mRomDownloadID + " and ID is " + id);
                return;
            } else {
                Intent i = new Intent(context, AvailableActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
        }
    }

    if (action.equals(MANIFEST_CHECK_BACKGROUND)) {
        if (DEBUGGING)
            Log.d(TAG, "Receiving background check confirmation");

        boolean updateAvailable = RomUpdate.getUpdateAvailability(context);
        String filename = RomUpdate.getFilename(context);

        if (updateAvailable) {
            Utils.setupNotification(context, filename);
            Utils.scheduleNotification(context, !Preferences.getBackgroundService(context));
        }
    }

    if (action.equals(START_UPDATE_CHECK)) {
        if (DEBUGGING)
            Log.d(TAG, "Update check started");
        new LoadUpdateManifest(context, false).execute();
    }

    if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        if (DEBUGGING) {
            Log.d(TAG, "Boot received");
        }
        boolean backgroundCheck = Preferences.getBackgroundService(context);
        if (backgroundCheck) {
            if (DEBUGGING)
                Log.d(TAG, "Starting background check alarm");
            Utils.scheduleNotification(context, !Preferences.getBackgroundService(context));
        }
    }

    if (action.equals(IGNORE_RELEASE)) {
        if (DEBUGGING) {
            Log.d(TAG, "Ignore release");
        }
        Preferences.setIgnoredRelease(context, Integer.toString(RomUpdate.getVersionNumber(context)));
        final NotificationManager mNotifyManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Builder mBuilder = new NotificationCompat.Builder(context);
        mBuilder.setContentTitle(context.getString(R.string.main_release_ignored))
                .setSmallIcon(R.drawable.ic_notif)
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0));
        mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

        Handler h = new Handler();
        long delayInMilliseconds = 1500;
        h.postDelayed(new Runnable() {

            public void run() {
                mNotifyManager.cancel(NOTIFICATION_ID);
            }
        }, delayInMilliseconds);
    }
}

From source file:org.messic.android.download.DownloadManagerService.java

public void onCreate() {
    super.onCreate();
    dm = (DownloadManager) getSystemService(Activity.DOWNLOAD_SERVICE);

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override/*from w  w  w.  jav a 2  s.co  m*/
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                saveCover(pendingDownloads.get(downloadId));
                pendingDownloads.remove(downloadId);
                // Uri uri = dm.getUriForDownloadedFile( downloadId );
                // System.out.println( uri );
                // dm.remove( downloadId );
            }
        }
    };
    registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:com.zeusky.star.star.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ///ww  w.  j  a  va  2 s. c  om
    m_instance = this;

    MainActivity.init(this);

    StatConfig.setDebugEnable(true);
    StatService.trackCustomEvent(this, "onCreate", "");

    ShareSDKUtils.prepare(); // share sdk
    methodsRun.injectIMEI(Util.getOpenid(this));

    createSharePicDir();

    this.registerReceiver(Util.receiver, new IntentFilter( // 
            DownloadManager.ACTION_DOWNLOAD_COMPLETE));

    // Util.openAPK();
}

From source file:org.amahi.anywhere.util.Downloader.java

private void setUpDownloadReceiver() {
    IntentFilter downloadActionsFilter = new IntentFilter();
    downloadActionsFilter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE);

    context.registerReceiver(this, downloadActionsFilter);
}

From source file:com.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;/*from   ww w.  ja  v  a  2s .co m*/

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(DL_KERNEL_ACTION)) {
        KernelInfo.FACTORY.clearUpdateNotif(context);
        KernelInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.nks.nksmod.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;//from   ww  w .j ava2  s .  c  o m

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
        /* } else if (action.equals(DL_KERNEL_ACTION)) {
            KernelInfo.FACTORY.clearUpdateNotif(context);
            KernelInfo.FACTORY.fromIntent(intent).startDownload(context); */
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.exercise.AndroidClient.AndroidClient.java

@Override
protected void onResume() {
    super.onResume();

    // register for download mgr notifications
    registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}