Example usage for android.app DownloadManager COLUMN_TITLE

List of usage examples for android.app DownloadManager COLUMN_TITLE

Introduction

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

Prototype

String COLUMN_TITLE

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

Click Source Link

Document

The client-supplied title for this download.

Usage

From source file:ru.appsm.inapphelp.service.AttachmentDownloadReceiver.java

private void downloadCompleted(Context context, Intent intent) {
    StringBuilder text = new StringBuilder();
    //Files are  ready
    String filename = context.getString(R.string.iah_attachment);
    String filepath = null;/*from  ww w. j  av  a  2s.c om*/
    String mediaType = null;
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
    Query query = new Query();
    query.setFilterById(downloadId);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        filepath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
        mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            text.append(context.getString(R.string.iah_download_complete));

        } else {
            text.append(context.getString(R.string.iah_error_during_download));
        }
    }

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

    NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(context);
    notificationbuilder.setAutoCancel(true);
    notificationbuilder.setContentText(text.toString());
    notificationbuilder.setContentTitle(filename);
    notificationbuilder.setSmallIcon(R.drawable.iah_notification_download_light_img);
    notificationbuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    notificationbuilder.setContentIntent(getPendingIntent(context));

    notificationManager.notify(filename, NOTIFICATION_ID, notificationbuilder.build());
}

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

private void downloadCompleted(Context context, Intent intent) {
    StringBuilder text = new StringBuilder();
    //Files are  ready
    String filename = context.getString(R.string.hs_attachment);
    String filepath = null;//from   www.j  a  va 2 s  . com
    String mediaType = null;
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
    Query query = new Query();
    query.setFilterById(downloadId);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        filepath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
        mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            text.append(context.getString(R.string.hs_download_complete));

        } else {
            text.append(context.getString(R.string.hs_error_during_download));
        }
    }

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

    NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(context);
    notificationbuilder.setAutoCancel(true);
    notificationbuilder.setContentText(text.toString());
    notificationbuilder.setContentTitle(filename);
    notificationbuilder.setSmallIcon(R.drawable.hs_notification_download_img);
    notificationbuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    notificationbuilder.setContentIntent(getPendingIntent(context));

    notificationManager.notify(filename, NOTIFICATION_ID, notificationbuilder.build());
}

From source file:com.example.linhdq.test.main_menu.language.OCRLanguageActivity.java

private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) {
    if (adapter != null) {
        // find languages that are currently being downloaded
        Query query = new Query();
        query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_PAUSED);
        final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        Cursor c = dm.query(query);
        if (c == null) {
            return;
        }//from   w  w  w.  j  ava 2 s  .com
        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
        while (c.moveToNext()) {
            final String title = c.getString(columnIndex);
            adapter.setDownloading(title, true);
        }
        adapter.notifyDataSetChanged();
        c.close();
    }
}

From source file:com.renard.ocr.help.OCRLanguageActivity.java

private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) {
    if (adapter != null) {
        // find languages that are currently beeing downloaded
        Query query = new Query();
        query.setFilterByStatus(DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_PAUSED);
        final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        Cursor c = dm.query(query);
        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
        while (c.moveToNext()) {
            final String title = c.getString(columnIndex);
            adapter.setDownloading(title, true);
        }//from  w ww  .j a  v a2 s .co m
        adapter.notifyDataSetChanged();
        c.close();
    }
}

From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java

private synchronized void downloadDictionary(final String downloadUrl, long bytes, Button downloadButton) {
    String destFile;//from   w w  w.  j  a v  a  2s .c  om
    try {
        destFile = new File(new URL(downloadUrl).getPath()).getName();
    } catch (MalformedURLException e) {
        throw new RuntimeException("Invalid download URL!", e);
    }
    DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    final DownloadManager.Query query = new DownloadManager.Query();
    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, R.string.downloadManagerQueryFailed))
                .setNeutralButton("Close", null).show();
        return;
    }

    while (cursor.moveToNext()) {
        if (downloadUrl.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_URI))))
            break;
        if (destFile.equals(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TITLE))))
            break;
    }
    if (!cursor.isAfterLast()) {
        downloadManager.remove(cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)));
        downloadButton.setText(getString(R.string.downloadButton, bytes / 1024.0 / 1024.0));
        cursor.close();
        return;
    }
    cursor.close();
    Request request = new Request(Uri.parse(downloadUrl));

    Log.d(LOG, "Downloading to: " + destFile);
    request.setTitle(destFile);

    File destFilePath = new File(application.getDictDir(), destFile);
    destFilePath.delete();
    try {
        request.setDestinationUri(Uri.fromFile(destFilePath));
    } catch (Exception e) {
    }

    try {
        downloadManager.enqueue(request);
    } catch (SecurityException e) {
        request = new Request(Uri.parse(downloadUrl));
        request.setTitle(destFile);
        downloadManager.enqueue(request);
    }
    Log.w(LOG, "Download started: " + destFile);
    downloadButton.setText("X");
}