Java Code Examples for android.app.DownloadManager.Query#setFilterById()
The following examples show how to use
android.app.DownloadManager.Query#setFilterById() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IDownloadManagerImpl.java From edx-app-android with Apache License 2.0 | 6 votes |
@Override public synchronized NativeDownloadModel getProgressDetailsForDownloads(long[] dmids) { //Need to check first if the download manager service is enabled if (!isDownloadManagerEnabled()) return null; final NativeDownloadModel downloadProgressModel = new NativeDownloadModel(); final Query query = new Query(); query.setFilterById(dmids); final Cursor c = dm.query(query); if (c.moveToFirst()) { downloadProgressModel.downloadCount = c.getCount(); do { downloadProgressModel.downloaded += c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); downloadProgressModel.size += c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); } while (c.moveToNext()); c.close(); return downloadProgressModel; } c.close(); return null; }
Example 2
Source File: IDownloadManagerImpl.java From edx-app-android with Apache License 2.0 | 6 votes |
@Override public synchronized boolean isDownloadComplete(long dmid) { //Need to check first if the download manager service is enabled if(!isDownloadManagerEnabled()) return false; Query query = new Query(); query.setFilterById(dmid); Cursor c = dm.query(query); if (c.moveToFirst()) { int status = c.getInt(c .getColumnIndex(DownloadManager.COLUMN_STATUS)); c.close(); return (status == DownloadManager.STATUS_SUCCESSFUL); } c.close(); return false; }
Example 3
Source File: MapDownloadUnzip.java From PocketMaps with MIT License | 5 votes |
public static int getDownloadStatus(Context context, long enqueueId) { Query query = new Query(); DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); query.setFilterById(enqueueId); Cursor c = dm.query(query); if (c.moveToFirst()) { int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); return c.getInt(columnIndex); } return -1; // Aborted. }
Example 4
Source File: IDownloadManagerImpl.java From edx-app-android with Apache License 2.0 | 5 votes |
@Override public synchronized int getAverageProgressForDownloads(long[] dmids) { //Need to check first if the download manager service is enabled if(!isDownloadManagerEnabled()) return 0; Query query = new Query(); query.setFilterById(dmids); try { Cursor c = dm.query(query); if (c.moveToFirst()) { int count = c.getCount(); float aggrPercent = 0; do { long downloaded = c .getLong(c .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); long size = c.getLong(c .getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); aggrPercent += (100f * downloaded / size); } while (c.moveToNext()); c.close(); int average = (int) (aggrPercent / count); return average; } c.close(); }catch (Exception ex){ logger.debug(ex.getMessage()); } return 0; }
Example 5
Source File: PluginDownloader.java From geoar-app with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); synchronized (currentDownloads) { if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action) && !currentDownloads.isEmpty()) { // long downloadId = intent.getLongExtra( // DownloadManager.EXTRA_DOWNLOAD_ID, 0); Query query = new Query(); long[] downloads = new long[currentDownloads.size()]; for (int i = 0, len = currentDownloads.size(); i < len; i++) { downloads[i] = currentDownloads.get(i); } query.setFilterById(downloads); query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL); Cursor cursor = mDownloadManager.query(query); boolean pluginAdded = false; if (cursor.moveToFirst()) { int columnId = cursor .getColumnIndex(DownloadManager.COLUMN_ID); do { currentDownloads.remove(cursor.getLong(columnId)); pluginAdded = true; } while (cursor.moveToNext()); if (pluginAdded) { PluginLoader.reloadPlugins(); } } } } }
Example 6
Source File: DownloadManagerActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); BroadcastReceiver receiver = 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); Query query = new Query(); query.setFilterById(enqueue); Cursor c = dm.query(query); if (c.moveToFirst()) { int columnIndex = c .getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c .getInt(columnIndex)) { ImageView view = (ImageView) findViewById(R.id.imageView1); String uriString = c .getString(c .getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); view.setImageURI(Uri.parse(uriString)); } } } } }; registerReceiver(receiver, new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
Example 7
Source File: SplashActivity.java From pokemon-go-xposed-mitm with GNU General Public License v3.0 | 4 votes |
private void registerPackageInstallReceiver() { receiver = new BroadcastReceiver(){ public void onReceive(Context context, Intent intent) { Log.d("Received intent: " + intent + " (" + intent.getExtras() + ")"); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); if (downloadId == enqueue) { if (localFile.exists()) { return; } Query query = new Query(); query.setFilterById(enqueue); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToFirst()) { hideProgress(); int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); if (DownloadManager.STATUS_SUCCESSFUL == status) { storeDownload(dm, downloadId); installDownload(); } else { int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON)); Toast.makeText(context,"Download failed (" + status + "): " + reason, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(context,"Download diappeared!", Toast.LENGTH_LONG).show(); } c.close(); } } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { if (intent.getData().toString().equals("package:org.ruboto.core")) { Toast.makeText(context,"Ruboto Core is now installed.",Toast.LENGTH_LONG).show(); deleteFile(RUBOTO_APK); if (receiver != null) { unregisterReceiver(receiver); receiver = null; } initJRuby(false); } else { Toast.makeText(context,"Installed: " + intent.getData().toString(),Toast.LENGTH_LONG).show(); } } } }; IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addDataScheme("package"); registerReceiver(receiver, filter); IntentFilter download_filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); registerReceiver(receiver, download_filter); }
Example 8
Source File: IDownloadManagerImpl.java From edx-app-android with Apache License 2.0 | 4 votes |
@Override public synchronized NativeDownloadModel getDownload(long dmid) { //Need to check first if the download manager service is enabled if(!isDownloadManagerEnabled()) return null; try { Query query = new Query(); query.setFilterById(dmid); Cursor cursor = dm.query(query); if (cursor.moveToFirst()) { long downloaded = cursor.getLong(cursor .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); long size = cursor.getLong(cursor .getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); String filepath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { if (filepath != null) { filepath = Uri.parse(filepath).getPath(); } } else { filepath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME)); } int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); cursor.close(); NativeDownloadModel ndm = new NativeDownloadModel(); ndm.dmid = dmid; ndm.downloaded = downloaded; ndm.size = size; ndm.filepath = filepath; ndm.status = status; return ndm; } cursor.close(); } catch(Exception e) { logger.error(e); } return null; }
Example 9
Source File: DownloadCompleteReveiver.java From WayHoo with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); if (id == Preferences.getDownloadId(context)) { Query query = new Query(); query.setFilterById(id); downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); Cursor cursor = downloadManager.query(query); int columnCount = cursor.getColumnCount(); String path = null; while (cursor.moveToNext()) { for (int j = 0; j < columnCount; j++) { String columnName = cursor.getColumnName(j); String string = cursor.getString(j); if ("local_uri".equals(columnName)) { path = string; } } } cursor.close(); if (path != null) { Preferences.setDownloadPath(context, path); Preferences.setDownloadStatus(context, -1); Intent installApkIntent = new Intent(); installApkIntent.setAction(Intent.ACTION_VIEW); installApkIntent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive"); installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); context.startActivity(installApkIntent); } } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent .getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) { Intent downloadIntent = new Intent(); downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS); downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); context.startActivity(downloadIntent); } } }
Example 10
Source File: DownloadCompleteReveiver.java From WayHoo with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); if (id == Preferences.getDownloadId(context)) { Query query = new Query(); query.setFilterById(id); downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); Cursor cursor = downloadManager.query(query); int columnCount = cursor.getColumnCount(); String path = null; while (cursor.moveToNext()) { for (int j = 0; j < columnCount; j++) { String columnName = cursor.getColumnName(j); String string = cursor.getString(j); if ("local_uri".equals(columnName)) { path = string; } } } cursor.close(); if (path != null) { Preferences.setDownloadPath(context, path); Preferences.setDownloadStatus(context, -1); Intent installApkIntent = new Intent(); installApkIntent.setAction(Intent.ACTION_VIEW); installApkIntent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive"); installApkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); context.startActivity(installApkIntent); } } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent .getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length > 0 && ids[0] == Preferences.getDownloadId(context)) { Intent downloadIntent = new Intent(); downloadIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS); downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); context.startActivity(downloadIntent); } } }