List of usage examples for android.app DownloadManager COLUMN_LOCAL_URI
String COLUMN_LOCAL_URI
To view the source code for android.app DownloadManager COLUMN_LOCAL_URI.
Click Source Link
From source file:Main.java
/** * Find a download with the specified name. Returns -1 if none was * found./* www.ja va 2 s.c o m*/ */ static long findPath(DownloadManager dm, String path) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = dm.query(query); if (!c.moveToFirst()) return -1; final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID); final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI); do { final String uri = c.getString(columnLocalURI); if (uri != null && uri.endsWith(path)) return c.getLong(columnID); } while (c.moveToNext()); return -1; }
From source file:org.mozilla.focus.broadcastreceiver.DownloadBroadcastReceiver.java
private void displaySnackbar(final Context context, long completedDownloadReference, DownloadManager downloadManager) { if (!isFocusDownload(completedDownloadReference)) { return;/*from w w w. j a v a2 s. co m*/ } final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(completedDownloadReference); try (Cursor cursor = downloadManager.query(query)) { if (cursor.moveToFirst()) { int statusColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusColumnIndex)) { String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); final String localUri = uriString.startsWith(FILE_SCHEME) ? uriString.substring(FILE_SCHEME.length()) : uriString; final String fileExtension = MimeTypeMap.getFileExtensionFromUrl(localUri); final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); final String fileName = URLUtil.guessFileName(Uri.decode(localUri), null, mimeType); final File file = new File(Uri.decode(localUri)); final Uri uriForFile = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + FILE_PROVIDER_EXTENSION, file); final Intent openFileIntent = IntentUtils.createOpenFileIntent(uriForFile, mimeType); showSnackbarForFilename(openFileIntent, context, fileName); } } } removeFromHashSet(completedDownloadReference); }
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;/*w w w . j ava 2 s.c o m*/ 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 w ww.j a va2s .c o m*/ 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.commonsware.android.downmgr.DownloadFragment.java
private void queryStatus(View v) { Cursor c = mgr.query(new DownloadManager.Query().setFilterById(lastDownload)); if (c == null) { Toast.makeText(getActivity(), R.string.download_not_found, Toast.LENGTH_LONG).show(); } else {/*w w w . j a v a 2 s .c o m*/ c.moveToFirst(); Log.d(getClass().getName(), "COLUMN_ID: " + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID))); Log.d(getClass().getName(), "COLUMN_BYTES_DOWNLOADED_SO_FAR: " + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))); Log.d(getClass().getName(), "COLUMN_LAST_MODIFIED_TIMESTAMP: " + c.getLong(c.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP))); Log.d(getClass().getName(), "COLUMN_LOCAL_URI: " + c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))); Log.d(getClass().getName(), "COLUMN_STATUS: " + c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))); Log.d(getClass().getName(), "COLUMN_REASON: " + c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON))); Toast.makeText(getActivity(), statusMessage(c), Toast.LENGTH_LONG).show(); c.close(); } }
From source file:com.rdrive.updateapk.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_update = (Button) findViewById(R.id.button_update); btn_update.setEnabled(false);/* www. ja v a 2 s. c o m*/ currentVersionValue = (TextView) findViewById(R.id.currentVersionValue); lastVersionValue = (TextView) findViewById(R.id.lastVersionValue); dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); new CheckUpdate() { @Override protected void onPostExecute(Boolean aBoolean) { currentVersionValue.setText(this.getCurrentVersion().toString()); lastVersionValue.setText(this.getLastVersion().toString()); if (!aBoolean) { btn_update.setEnabled(true); } } }.execute(getContext()); btn_update.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT > 22) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, ASK_WRITE_EXTERNAL_STORAGE_FOR_UPDATE); return; } } downloadLastVersion(getContext(), dm); } }); BroadcastReceiver attachmentDownloadCompleteReceive = new BroadcastReceiver() { @Override 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); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); Cursor cursor = dm.query(query); if (cursor.moveToFirst()) { int downloadStatus = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); String downloadLocalUri = cursor .getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); if ((downloadStatus == DownloadManager.STATUS_SUCCESSFUL) && downloadLocalUri != null) { openApk(getContext(), downloadLocalUri); } } cursor.close(); } } }; registerReceiver(attachmentDownloadCompleteReceive, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:com.cypher.cota.helpers.DownloadHelper.java
private static void checkDownloadFinished(long downloadId, boolean installIfFinished) { long id = Long.parseLong(PreferenceUtils.getPreference(sContext, PreferenceUtils.DOWNLOAD_ROM_ID, "-1")); if (id == -1L || (downloadId != 0 && downloadId != id)) { return;//from w ww .j a va 2s . c o m } String md5 = PreferenceUtils.getPreference(sContext, PreferenceUtils.DOWNLOAD_ROM_MD5, null); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = sDownloadManager.query(query); if (cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = cursor.getInt(columnIndex); switch (status) { case DownloadManager.STATUS_FAILED: removeDownload(id, true); int reasonText = getDownloadError(cursor); sCallback.onDownloadError(sContext.getResources().getString(reasonText)); break; case DownloadManager.STATUS_SUCCESSFUL: if (installIfFinished) { String uriString = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); sCallback.onDownloadFinished(Uri.parse(uriString), md5); } downloadSuccesful(); break; default: cancelDownload(id); break; } } else { removeDownload(id, true); } cursor.close(); }
From source file:org.openbmap.activities.DialogPreferenceCatalogs.java
/** * Initialises download manager for GINGERBREAD and newer *///w w w . java2 s. c om @SuppressLint("NewApi") private void initDownloadManager() { mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE); mReceiver = new BroadcastReceiver() { @SuppressLint("NewApi") @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); final Cursor c = mDownloadManager.query(query); if (c.moveToFirst()) { final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { // we're not checking download id here, that is done in handleDownloads final String uriString = c .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); handleDownloads(uriString); } else { final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); Log.e(TAG, "Download failed: " + reason); } } } } }; getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:org.openbmap.activities.DialogPreferenceMaps.java
/** * Initialises download manager for GINGERBREAD and newer *//* w w w.j a v a2 s. c om*/ @SuppressLint("NewApi") private void initDownloadManager() { mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE); mReceiver = new BroadcastReceiver() { @SuppressLint("NewApi") @Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); final DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(downloadId); final Cursor c = mDownloadManager.query(query); if (c.moveToFirst()) { final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { // we're not checking download id here, that is done in handleDownloads final String uriString = c .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); handleDownloads(uriString); } else { final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); Log.e(TAG, "Download failed: " + reason); } } } } }; getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:org.amahi.anywhere.util.Downloader.java
private void finishDownloading() { DownloadManager.Query downloadQuery = new DownloadManager.Query().setFilterById(downloadId); Cursor downloadInformation = getDownloadManager(context).query(downloadQuery); downloadInformation.moveToFirst();/*from www .j a va2 s .c o m*/ int downloadStatus = downloadInformation .getInt(downloadInformation.getColumnIndex(DownloadManager.COLUMN_STATUS)); if (downloadStatus == DownloadManager.STATUS_SUCCESSFUL) { String downloadUri = downloadInformation .getString(downloadInformation.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); if (downloadUri.substring(0, 7).matches("file://")) { downloadUri = downloadUri.substring(7); } try { URI uri = new URI(downloadUri); downloadUri = uri.getPath(); } catch (URISyntaxException e) { Log.e("Downloader", "Invalid Uri: " + downloadUri); } File file = new File(downloadUri); Uri contentUri = FileProvider.getUriForFile(context, "org.amahi.anywhere.fileprovider", file); BusProvider.getBus().post(new FileDownloadedEvent(contentUri)); } else { BusProvider.getBus().post(new FileDownloadFailedEvent()); } downloadInformation.close(); }