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.appjma.appdeployer.adapter.DownloadLoader.java
public DownloadLoader(Context context) { super(context); mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); }
From source file:com.btmura.android.reddit.app.MenuHelper.java
public static void downloadUrl(Context context, String title, String url) { context = context.getApplicationContext(); DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); Request request = new Request(Uri.parse(url)); request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setTitle(title);//from w w w . ja v a 2 s . co m manager.enqueue(request); }
From source file:de.escoand.readdaily.DownloadHandler.java
public static long startDownload(@NonNull final Context context, @NonNull final String signature, @NonNull final String responseData, @NonNull final String title, @Nullable final String mimeType) { final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); String name;//from w ww.j ava 2 s .c om try { name = new JSONObject(responseData).getString("productId"); } catch (JSONException e) { LogHandler.log(e); return -1; } LogHandler.log(Log.WARN, "load " + name); long id = manager .enqueue(new DownloadManager.Request(Uri.parse(context.getString(R.string.product_data_url))) .addRequestHeader("App-Signature", signature) .addRequestHeader("App-ResponseData", responseData).setTitle(title) .setDescription(context.getString(R.string.app_title))); Database.getInstance(context).addDownload(name, id, mimeType); return id; }
From source file:com.exercise.AndroidClient.AndroidClient.java
/** Called when the activity is first created. */ @Override//from www. j a v a2 s. com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textOut = (EditText) findViewById(R.id.textout); downloadMgr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); }
From source file:com.commonsware.android.downmgr.DownloadFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { mgr = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE); View result = inflater.inflate(R.layout.main, parent, false); query = result.findViewById(R.id.query); query.setOnClickListener(this); start = result.findViewById(R.id.start); start.setOnClickListener(this); result.findViewById(R.id.view).setOnClickListener(this); return (result); }
From source file:it.rignanese.leo.slimfacebook.PictureActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_picture); savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // setup the sharedPreferences downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); BroadcastReceiver receiver = downloadCompletedReceiver; registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); SetupPictureWebView();//from w w w. j a v a 2 s. c om String pictureUrl = getIntent().getStringExtra("URL"); webViewPicture.loadUrl(pictureUrl); }
From source file:com.otaupdater.DownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return;/*w w w.ja v a 2s. co m*/ if (action.equals(DL_ROM_ACTION)) { RomInfo.FACTORY.clearUpdateNotif(context); RomInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(DL_KERNEL_ACTION)) { KernelInfo.FACTORY.clearUpdateNotif(context); KernelInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(CLEAR_DL_ACTION)) { if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); DownloadBarFragment.notifyActiveFragment(); } } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { DownloadStatus status = DownloadStatus.forDownloadID(context, intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile() : status.getReason(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (error == 0) { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent flashIntent = new Intent(context, DownloadsActivity.class); flashIntent.setAction(info.getFlashAction()); info.addToIntent(flashIntent); PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadDoneTitle())) .setContentTitle(context.getString(info.getDownloadDoneTitle())) .setSmallIcon(R.drawable.ic_stat_av_download) .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent) .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install), flashPIntent) .build(); nm.notify(info.getFlashNotifID(), notif); } else { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); info.addToIntent(mainIntent); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlIntent = new Intent(context, DownloadReceiver.class); dlIntent.setAction(info.getDownloadAction()); info.addToIntent(dlIntent); PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent clearIntent = new Intent(context, DownloadReceiver.class); clearIntent.setAction(CLEAR_DL_ACTION); clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId()); PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadFailedTitle())) .setContentTitle(context.getString(info.getDownloadFailedTitle())) .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning) .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent) .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent) .build(); nm.notify(info.getFailedNotifID(), notif); } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length == 0) return; DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; Intent i = new Intent(context, OTAUpdaterActivity.class); i.setAction(info.getNotifAction()); i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
From source file:com.renard.ocr.help.OCRLanguageInstallService.java
@Override protected void onHandleIntent(Intent intent) { if (!intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { return;//from w w w .ja va 2s . c om } final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0); if (downloadId != 0) { DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); ParcelFileDescriptor file; try { file = dm.openDownloadedFile(downloadId); FileInputStream fin = new FileInputStream(file.getFileDescriptor()); BufferedInputStream in = new BufferedInputStream(fin); FileOutputStream out = openFileOutput("tess-lang.tmp", Context.MODE_PRIVATE); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); final byte[] buffer = new byte[2048 * 2]; int n = 0; while (-1 != (n = gzIn.read(buffer))) { out.write(buffer, 0, n); } out.close(); gzIn.close(); FileInputStream fileIn = openFileInput("tess-lang.tmp"); TarArchiveInputStream tarIn = new TarArchiveInputStream(fileIn); TarArchiveEntry entry = tarIn.getNextTarEntry(); while (entry != null && !(entry.getName().endsWith(".traineddata") && !entry.getName().endsWith("_old.traineddata"))) { entry = tarIn.getNextTarEntry(); } if (entry != null) { File tessDir = Util.getTrainingDataDir(this); final String langName = entry.getName().substring("tesseract-ocr/tessdata/".length()); File trainedData = new File(tessDir, langName); FileOutputStream fout = new FileOutputStream(trainedData); int len; while ((len = tarIn.read(buffer)) != -1) { fout.write(buffer, 0, len); } fout.close(); String lang = langName.substring(0, langName.length() - ".traineddata".length()); notifyReceivers(lang); } tarIn.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { String tessDir = Util.getTessDir(this); File targetFile = new File(tessDir, OCRLanguageActivity.DOWNLOADED_TRAINING_DATA); if (targetFile.exists()) { targetFile.delete(); } } } }
From source file:com.nks.nksmod.otaupdater.DownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return;// w w w . j av a 2 s .c om if (action.equals(DL_ROM_ACTION)) { RomInfo.FACTORY.clearUpdateNotif(context); RomInfo.FACTORY.fromIntent(intent).startDownload(context); /* } else if (action.equals(DL_KERNEL_ACTION)) { KernelInfo.FACTORY.clearUpdateNotif(context); KernelInfo.FACTORY.fromIntent(intent).startDownload(context); */ } else if (action.equals(CLEAR_DL_ACTION)) { if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); DownloadBarFragment.notifyActiveFragment(); } } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { DownloadStatus status = DownloadStatus.forDownloadID(context, intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile() : status.getReason(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (error == 0) { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent flashIntent = new Intent(context, DownloadsActivity.class); flashIntent.setAction(info.getFlashAction()); info.addToIntent(flashIntent); PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadDoneTitle())) .setContentTitle(context.getString(info.getDownloadDoneTitle())) .setSmallIcon(R.drawable.ic_stat_av_download) .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent) .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install), flashPIntent) .build(); nm.notify(info.getFlashNotifID(), notif); } else { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); info.addToIntent(mainIntent); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlIntent = new Intent(context, DownloadReceiver.class); dlIntent.setAction(info.getDownloadAction()); info.addToIntent(dlIntent); PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent clearIntent = new Intent(context, DownloadReceiver.class); clearIntent.setAction(CLEAR_DL_ACTION); clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId()); PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadFailedTitle())) .setContentTitle(context.getString(info.getDownloadFailedTitle())) .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning) .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent) .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent) .build(); nm.notify(info.getFailedNotifID(), notif); } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length == 0) return; DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; Intent i = new Intent(context, OTAUpdaterActivity.class); i.setAction(info.getNotifAction()); i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
From source file:com.giovanniterlingen.windesheim.controllers.WebViewController.java
public WebView createWebView() { WebView webView = new WebView(activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { int lastSlash = url.lastIndexOf('/'); String fileName = url.substring(lastSlash + 1); DownloadManager downloadManager = (DownloadManager) activity .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.addRequestHeader("Cookie", new CookieController().getNatSchoolCookie()).setTitle(fileName) .setDescription(activity.getResources().getString(R.string.downloading)) .setDestinationInExternalPublicDir(File.separator + ApplicationLoader.applicationContext.getResources().getString(R.string.app_name), fileName)//from w ww . j a va 2 s.co m .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); downloadManager.enqueue(request); } }); return webView; }