List of usage examples for android.content Context DOWNLOAD_SERVICE
String DOWNLOAD_SERVICE
To view the source code for android.content Context DOWNLOAD_SERVICE.
Click Source Link
From source file:com.murrayc.galaxyzoo.app.SubjectFragment.java
private void doDownloadImage() { //We download the image from the remote server again, //even though we already have it in the ContentProvider, //available via the mUriImageStandard content: URI, //just to get it into the DownloadManager UI. //Unfortunately the DownloadManager rejects content: URIs. if (TextUtils.isEmpty(mUriStandardRemote)) { Log.error("doDownloadImage(): mUriStandardRemote was null."); return;/* w ww.j av a2 s .c o m*/ } final Uri uri = Uri.parse(mUriStandardRemote); if (uri == null) { Log.error("doDownloadImage(): uri was null."); return; } final DownloadManager.Request request = new DownloadManager.Request(uri); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); final Activity activity = getActivity(); if (activity == null) { Log.error("doDownloadImage(): activity was null."); return; } final Object systemService = activity.getSystemService(Context.DOWNLOAD_SERVICE); if (systemService == null || !(systemService instanceof DownloadManager)) { Log.error("doDownloadImage(): Could not get DOWNLOAD_SERVICE."); return; } final DownloadManager downloadManager = (DownloadManager) systemService; downloadManager.enqueue(request); }
From source file:com.seal.ui.components.CustomWebView.java
@Override public void onAcceptDownload(DownloadItem item) { long id = ((DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(item); item.setId(id);/* ww w .j a va 2 s .c o m*/ Controller.getInstance().getDownloadsList().add(item); Toast.makeText(mContext, String.format(mContext.getString(R.string.DownloadStart), item.getFileName()), Toast.LENGTH_SHORT).show(); }
From source file:com.oakesville.mythling.app.AppData.java
public Map<String, Download> getDownloads() throws IOException, JSONException, ParseException { readDownloads();/* w w w . ja va 2 s.c o m*/ DownloadManager dm = (DownloadManager) appContext.getSystemService(Context.DOWNLOAD_SERVICE); Map<String, Download> filtered = new HashMap<String, Download>(); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -7); long lastWeek = cal.getTimeInMillis(); List<String> itemsToRemove = null; for (String itemId : downloads.keySet()) { Download download = downloads.get(itemId); if (dm.getUriForDownloadedFile(download.getDownloadId()) != null) // make sure the file exists filtered.put(itemId, download); else if (lastWeek > download.getStarted().getTime()) { // remove missing items older than a week if (itemsToRemove == null) itemsToRemove = new ArrayList<String>(); itemsToRemove.add(download.getItemId()); } } if (itemsToRemove != null) { for (String itemToRemove : itemsToRemove) downloads.remove(itemToRemove); persistDownloads(); } return filtered; }
From source file:com.nick.scalpel.core.AutoFoundWirer.java
private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme, Field field, Object forWho) { Resources resources = context.getResources(); switch (type) { case STRING:/*from w w w.j ava2 s .com*/ setField(field, forWho, resources.getString(idRes)); break; case COLOR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, resources.getColor(idRes, theme)); } else { //noinspection deprecation setField(field, forWho, resources.getColor(idRes)); } break; case INTEGER: setField(field, forWho, resources.getInteger(idRes)); break; case BOOL: setField(field, forWho, resources.getBoolean(idRes)); break; case STRING_ARRAY: setField(field, forWho, resources.getStringArray(idRes)); break; case INT_ARRAY: setField(field, forWho, resources.getIntArray(idRes)); break; case PM: setField(field, forWho, context.getSystemService(Context.POWER_SERVICE)); break; case ACCOUNT: setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE)); break; case ALARM: setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE)); break; case AM: setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE)); break; case WM: setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE)); break; case NM: setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE)); break; case TM: setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE)); break; case TCM: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE)); } break; case SP: setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context)); break; case PKM: setField(field, forWho, context.getPackageManager()); break; case HANDLE: setField(field, forWho, new Handler(Looper.getMainLooper())); break; case ASM: setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE)); break; case CAP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE)); } break; case KGD: setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE)); break; case LOCATION: setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE)); break; case SEARCH: setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE)); break; case SENSOR: setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE)); break; case STORAGE: setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE)); break; case WALLPAPER: setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE)); break; case VIBRATOR: setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE)); break; case CONNECT: setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE)); break; case NETWORK_STATUS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE)); } break; case WIFI: setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE)); break; case AUDIO: setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE)); break; case FP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE)); } break; case MEDIA_ROUTER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE)); } break; case SUB: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)); } break; case IME: setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE)); break; case CLIP_BOARD: setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE)); break; case APP_WIDGET: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE)); } break; case DEVICE_POLICY: setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE)); break; case DOWNLOAD: setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE)); break; case BATTERY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE)); } break; case NFC: setField(field, forWho, context.getSystemService(Context.NFC_SERVICE)); break; case DISPLAY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE)); } break; case USER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.USER_SERVICE)); } break; case APP_OPS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE)); } break; case BITMAP: setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null)); break; } }
From source file:com.otaupdater.utils.RomInfo.java
public void showUpdateDialog(final Context ctx) { AlertDialog.Builder alert = new AlertDialog.Builder(ctx); alert.setTitle(R.string.alert_update_title); alert.setMessage(ctx.getString(R.string.alert_update_rom_to, romName, version)); alert.setPositiveButton(R.string.alert_download, new DialogInterface.OnClickListener() { @Override/*from w ww. ja v a 2s .c om*/ public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); final File file = new File(Config.ROM_DL_PATH_FILE, getDownloadFileName()); if (file.exists()) { Log.v("OTA::Download", "Found old zip, checking md5"); InputStream is = null; try { is = new FileInputStream(file); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] data = new byte[4096]; int nRead = -1; while ((nRead = is.read(data)) != -1) { digest.update(data, 0, nRead); } String oldMd5 = Utils.byteArrToStr(digest.digest()); Log.v("OTA::Download", "old zip md5: " + oldMd5); if (!md5.equalsIgnoreCase(oldMd5)) { file.delete(); } else { //TODO show flash dialog return; } } catch (Exception e) { e.printStackTrace(); file.delete(); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } } final long dlID = fetchFile(ctx); AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.alert_downloading); builder.setMessage(ctx.getString(R.string.alert_downloading_changelog, changelog)); builder.setCancelable(true); builder.setPositiveButton(R.string.alert_hide, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(dlID); } }); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.create().show(); }
From source file:com.otaupdater.utils.KernelInfo.java
public void showUpdateDialog(final Context ctx) { AlertDialog.Builder alert = new AlertDialog.Builder(ctx); alert.setTitle(R.string.alert_update_title); alert.setMessage(ctx.getString(R.string.alert_update_kernel_to, kernelName, version)); alert.setPositiveButton(R.string.alert_download, new DialogInterface.OnClickListener() { @Override/*from w ww . jav a2 s . com*/ public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); final File file = new File(Config.KERNEL_DL_PATH_FILE, getDownloadFileName()); if (file.exists()) { Log.v("OTA::Download", "Found old zip, checking md5"); InputStream is = null; try { is = new FileInputStream(file); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] data = new byte[4096]; int nRead = -1; while ((nRead = is.read(data)) != -1) { digest.update(data, 0, nRead); } String oldMd5 = Utils.byteArrToStr(digest.digest()); Log.v("OTA::Download", "old zip md5: " + oldMd5); if (!md5.equalsIgnoreCase(oldMd5)) { file.delete(); } else { //TODO show flash dialog return; } } catch (Exception e) { e.printStackTrace(); file.delete(); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } } final long dlID = fetchFile(ctx); AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.alert_downloading); builder.setMessage(ctx.getString(R.string.alert_downloading_changelog, changelog)); builder.setCancelable(true); builder.setPositiveButton(R.string.alert_hide, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(dlID); } }); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.create().show(); }
From source file:org.apache.cordova.backgroundDownload.BackgroundDownload.java
private void StartProgressTracking(final Download curDownload) { // already started if (curDownload.getTimerProgressUpdate() != null) { return;/* www . java2 s . c o m*/ } final DownloadManager mgr = (DownloadManager) this.cordova.getActivity() .getSystemService(Context.DOWNLOAD_SERVICE); curDownload.setTimerProgressUpdate(new Timer()); curDownload.getTimerProgressUpdate().schedule(new TimerTask() { @Override public void run() { DownloadManager.Query q = new DownloadManager.Query(); q.setFilterById(curDownload.getDownloadId()); Cursor cursor = mgr.query(q); if (cursor.moveToFirst()) { long bytesDownloaded = cursor .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); long bytesTotal = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); if (bytesTotal != -1) { Log.d("BackgroundDownload", "DOWNLOAD STARTED for " + curDownload.getDownloadId()); try { JSONObject jsonProgress = new JSONObject(); jsonProgress.put("bytesReceived", bytesDownloaded); jsonProgress.put("totalBytesToReceive", bytesTotal); JSONObject obj = new JSONObject(); obj.put("progress", jsonProgress); PluginResult progressUpdate = new PluginResult(PluginResult.Status.OK, obj); progressUpdate.setKeepCallback(true); curDownload.getCallbackContextDownloadStart().sendPluginResult(progressUpdate); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { long status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)); long reason = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_REASON)); Log.d("BackgroundDownload", "download not started for " + curDownload.getTempFilePath() + " (status " + status + ") (reason " + reason + ")"); } } cursor.close(); } }, DOWNLOAD_PROGRESS_UPDATE_TIMEOUT, DOWNLOAD_PROGRESS_UPDATE_TIMEOUT); }
From source file:com.zsxj.pda.ui.client.LoginActivity.java
private boolean downloading() { DownloadManager.Query query = new DownloadManager.Query(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long downloadId = prefs.getLong(PrefKeys.DOWNLOAD_ID, 0); query.setFilterById(downloadId);//from w w w. ja va 2 s . co m DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToNext()) { int statusIdx = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(statusIdx); if (DownloadManager.STATUS_RUNNING == status) { return true; } } return false; }
From source file:com.bt.heliniumstudentapp.UpdateClass.java
protected static void downloadAPK() { File oldUpdate = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk"); if (oldUpdate.exists()) //noinspection ResultOfMethodCallIgnored oldUpdate.delete();//from w w w . j a va 2s . co m if (MainActivity.isOnline()) { DownloadManager.Request request; request = new DownloadManager.Request(Uri.parse(HeliniumStudentApp.URL_UPDATE_RELEASE)); request.setTitle(context.getString(R.string.app_name) + " " + versionName); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/heliniumstudentapp.apk"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); context.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType( Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/heliniumstudentapp.apk")), "application/vnd.android.package-archive"); context.startActivity(install); } }, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } else { Toast.makeText(context, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } }
From source file:se.bitcraze.crazyfliecontrol.bootloader.FirmwareDownloader.java
public void downloadFile(String url, String fileName, String tagName) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription("Some description"); request.setTitle(fileName);//from ww w . j a v a2 s . com // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); } request.setDestinationInExternalFilesDir(mContext, null, BootloaderActivity.BOOTLOADER_DIR + "/" + tagName + "/" + fileName); // get download service and enqueue file mManager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); if (mManager != null) { mDownloadReference = mManager.enqueue(request); } else { Log.d(LOG_TAG, "DownloadManager could not be acquired."); ((BootloaderActivity) mContext).appendConsoleError( "DownloadManager could not be acquired.\nPlease check the application's permissions."); } }