Example usage for android.app DownloadManager COLUMN_LOCAL_FILENAME

List of usage examples for android.app DownloadManager COLUMN_LOCAL_FILENAME

Introduction

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

Prototype

String COLUMN_LOCAL_FILENAME

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

Click Source Link

Document

Path to the downloaded file on disk.

Usage

From source file:com.concentricsky.android.khanacademy.data.KADataService.java

private void updateDownloadStatus(Intent intent, final PendingIntent pendingIntent, final int startId) {
    final long id = intent.getLongExtra(EXTRA_ID, -1);
    final DownloadManager mgr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    final DownloadManager.Query q = new DownloadManager.Query();
    q.setFilterById(id);/*from w  w  w  .j  a va 2 s  .c  om*/

    new AsyncTask<Void, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Void... arg) {
            Cursor cursor = mgr.query(q);
            String youtubeId = null;
            int status = -1;
            if (cursor.moveToFirst()) {
                String filename = cursor
                        .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
                youtubeId = OfflineVideoManager.youtubeIdFromFilename(filename);
                status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
            }
            cursor.close();

            if (status == DownloadManager.STATUS_SUCCESSFUL && youtubeId != null) {
                try {
                    Dao<Video, String> videoDao = helper.getVideoDao();
                    UpdateBuilder<Video, String> q = videoDao.updateBuilder();
                    q.where().eq("youtube_id", youtubeId);
                    q.updateColumnValue("download_status", Video.DL_STATUS_COMPLETE);
                    q.update();
                    return true;
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            return false;
        }

        @Override
        protected void onPostExecute(Boolean successful) {
            if (successful) {
                broadcastOfflineVideoSetChanged();
                finish(startId, pendingIntent, RESULT_SUCCESS);
            } else {
                finish(startId, pendingIntent, RESULT_ERROR);
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

}

From source file:com.mobicage.rogerthat.plugins.messaging.BrandingMgr.java

@SuppressLint("InlinedApi")
private File getDownloadedFile(final Long downloadId) throws DownloadNotCompletedException {
    final DownloadManager dwnlMgr = getDownloadManager();
    final Cursor cursor = dwnlMgr.query(new Query().setFilterById(downloadId));
    try {/* w w  w  .j  a  v  a2 s .  com*/
        if (!cursor.moveToFirst()) {
            L.w("Download with id " + downloadId + " not found!");
            return null;
        }

        final int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
        switch (status) {
        case DownloadManager.STATUS_SUCCESSFUL:
            final String filePath = cursor
                    .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
            return new File(filePath);
        case DownloadManager.STATUS_FAILED:
            return null;
        default: // Not completed
            L.w("Unexpected DownloadManager.STATUS: " + status);
            throw new BrandingMgr.DownloadNotCompletedException();
        }
    } finally {
        cursor.close();
    }
}