List of usage examples for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE
String ACTION_DOWNLOAD_COMPLETE
To view the source code for android.app DownloadManager ACTION_DOWNLOAD_COMPLETE.
Click Source Link
From source file:dentex.youtube.downloader.ShareActivity.java
@Override protected void onStart() { super.onStart(); registerReceiver(inAppCompleteReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); Utils.logger("v", "_onStart", DEBUG_TAG); }
From source file:com.oakesville.mythling.MediaActivity.java
private void registerDownloadReceiver(Item item, long downloadId) { if (downloadReceivers == null) downloadReceivers = new HashMap<Long, DownloadBroadcastReceiver>(); DownloadBroadcastReceiver receiver = downloadReceivers.get(downloadId); if (receiver != null) { unregisterDownloadReceiver(downloadId); downloadReceivers.remove(downloadId); }/* ww w. j a v a 2s.co m*/ receiver = new DownloadBroadcastReceiver(item, downloadId); registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); downloadReceivers.put(downloadId, receiver); }
From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // This must be first, otherwise the actiona bar doesn't get // styled properly. setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId); super.onCreate(savedInstanceState); Log.d(LOG, "onCreate:" + this); application = (DictionaryApplication) getApplication(); blockAutoLaunch = false;//from w w w . j a v a2s .c o m // UI init. setContentView(R.layout.dictionary_manager_activity); dictionariesOnDeviceHeaderRow = (LinearLayout) LayoutInflater.from(getListView().getContext()) .inflate(R.layout.dictionary_manager_header_row_on_device, getListView(), false); downloadableDictionariesHeaderRow = (LinearLayout) LayoutInflater.from(getListView().getContext()) .inflate(R.layout.dictionary_manager_header_row_downloadable, getListView(), false); showDownloadable = (ToggleButton) downloadableDictionariesHeaderRow.findViewById(R.id.hideDownloadable); showDownloadable.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { onShowDownloadableChanged(); } }); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final String thanksForUpdatingLatestVersion = getString(R.string.thanksForUpdatingVersion); if (!prefs.getString(C.THANKS_FOR_UPDATING_VERSION, "").equals(thanksForUpdatingLatestVersion)) { blockAutoLaunch = true; startActivity(HtmlDisplayActivity.getWhatsNewLaunchIntent(getApplicationContext())); prefs.edit().putString(C.THANKS_FOR_UPDATING_VERSION, thanksForUpdatingLatestVersion).commit(); } registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); setMyListAdapater(); registerForContextMenu(getListView()); getListView().setItemsCanFocus(true); readableCheckAndError(true); onCreateSetupActionBar(); }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
public void initDownloadComponents() { BroadcastReceiver receiver = new BroadcastReceiver() { @Override// w w w. j a v a2s . c o m public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { // } } }; context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); context.unregisterReceiver(receiver); }
From source file:com.android.providers.downloads.DownloadInfo.java
public void sendIntentIfRequested() { if (mPackage == null) { return;/* www . j a v a 2s . com*/ } Intent intent; if (mIsPublicApi) { intent = new Intent(DownloadManager.ACTION_DOWNLOAD_COMPLETE); intent.setPackage(mPackage); intent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, mId); } else { // legacy behavior if (mClass == null) { return; } intent = new Intent(Downloads.Impl.ACTION_DOWNLOAD_COMPLETED); intent.setClassName(mPackage, mClass); if (mExtras != null) { intent.putExtra(Downloads.Impl.COLUMN_NOTIFICATION_EXTRAS, mExtras); } // We only send the content: URI, for security reasons. Otherwise, malicious // applications would have an easier time spoofing download results by // sending spoofed intents. intent.setData(getMyDownloadsUri()); } mSystemFacade.sendBroadcast(intent); }
From source file:jupiter.broadcasting.live.holo.JBPlayer.java
public void DownLoad(String url) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); String ver = (av == 0) ? getString(R.string.audio) : getString(R.string.video); request.setDescription(getString(R.string.progress) + "(" + ver + ")..."); request.setTitle(getIntent().getStringExtra("title")); down.setClickable(false);/*from ww w.j av a 2 s .c o m*/ // 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_VISIBLE_NOTIFY_COMPLETED); } String ext = (av == 0) ? "mp3" : "mp4"; request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS + "/JB", getIntent().getStringExtra("title") + "." + ext); // get download service and enqueue file final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); final long enqueue = manager.enqueue(request); //register receiver to be notified when download finishes BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(enqueue); Cursor c = manager.query(query); if (c != null) { if (c.moveToFirst()) { int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) { Toast.makeText(getBaseContext(), "Finished", Toast.LENGTH_LONG).show(); hasit = true; down.setClickable(true); } } } } } }; registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:de.baumann.browser.Browser.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); final WebView.HitTestResult result = mWebView.getHitTestResult(); final MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final String url = result.getExtra(); switch (item.getItemId()) { //Save image to external memory case ID_SAVE_IMAGE: { registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); try { if (url != null) { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, helper_main.newFileName()); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); }/* w w w .j a v a 2 s.c om*/ } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } break; case ID_SHARE_IMAGE: if (url != null) { shareString = helper_main.newFileName(); shareFile = helper_main.newFile(); try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, shareString); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } registerReceiver(onComplete2, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } break; case ID_READ_LATER: if (url != null) { int domainInt = url.indexOf("//") + 2; final String domain = url.substring(domainInt, url.indexOf('/', domainInt)); try { final Database_ReadLater db = new Database_ReadLater(Browser.this); db.addBookmark(domain, url); db.close(); Snackbar.make(mWebView, R.string.readLater_added, Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } break; case ID_COPY_LINK: if (url != null) { ClipboardManager clipboard = (ClipboardManager) Browser.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } break; case ID_SHARE_LINK: if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); Browser.this.startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_share_link))); } break; } return true; } }; if (result.getType() == WebView.HitTestResult.IMAGE_TYPE) { menu.add(0, ID_SAVE_IMAGE, 0, getString(R.string.context_saveImage)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_IMAGE, 0, getString(R.string.context_shareImage)) .setOnMenuItemClickListener(handler); menu.add(0, ID_READ_LATER, 0, getString(R.string.context_readLater)) .setOnMenuItemClickListener(handler); } else if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) { menu.add(0, ID_COPY_LINK, 0, getString(R.string.menu_share_link_copy)) .setOnMenuItemClickListener(handler); menu.add(0, ID_SHARE_LINK, 0, getString(R.string.menu_share_link)).setOnMenuItemClickListener(handler); menu.add(0, ID_READ_LATER, 0, getString(R.string.context_readLater)) .setOnMenuItemClickListener(handler); } }
From source file:de.baumann.browser.Browser_right.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); final WebView.HitTestResult result = mWebView.getHitTestResult(); final String url = result.getExtra(); if (result.getType() == WebView.HitTestResult.IMAGE_TYPE) { final CharSequence[] options = { getString(R.string.context_saveImage), getString(R.string.context_shareImage), getString(R.string.context_readLater), getString(R.string.context_left) }; new AlertDialog.Builder(Browser_right.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); }//from w w w. j a va 2 s . c o m }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.context_saveImage))) { if (url != null) { try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, helper_main.newFileName()); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } } if (options[item].equals(getString(R.string.context_shareImage))) { if (url != null) { shareString = helper_main.newFileName(); shareFile = helper_main.newFile(mWebView); try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, shareString); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } registerReceiver(onComplete2, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_left))) { if (url != null) { helper_main.switchToActivity(Browser_right.this, Browser_left.class, url, false); } } } }).show(); } else if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) { final CharSequence[] options = { getString(R.string.menu_share_link_copy), getString(R.string.menu_share_link), getString(R.string.context_readLater), getString(R.string.context_left) }; new AlertDialog.Builder(Browser_right.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link_copy))) { if (url != null) { ClipboardManager clipboard = (ClipboardManager) Browser_right.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } if (options[item].equals(getString(R.string.menu_share_link))) { if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); Browser_right.this.startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_share_link))); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_left))) { if (url != null) { helper_main.switchToActivity(Browser_right.this, Browser_left.class, url, false); } } } }).show(); } }
From source file:org.chromium.chrome.browser.download.DownloadManagerService.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (!DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) return;/*from ww w . j a v a 2 s . c om*/ final DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); if (downloadId == -1) return; boolean isPendingOMADownload = mOMADownloadHandler.isPendingOMADownload(downloadId); boolean isInOMASharedPrefs = isDownloadIdInOMASharedPrefs(downloadId); if (isPendingOMADownload || isInOMASharedPrefs) { clearPendingOMADownload(downloadId, null); mPendingAutoOpenDownloads.remove(downloadId); } else if (mPendingAutoOpenDownloads.get(downloadId) != null) { Cursor c = manager.query(new DownloadManager.Query().setFilterById(downloadId)); int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); while (c.moveToNext()) { int status = c.getInt(statusIndex); DownloadInfo info = mPendingAutoOpenDownloads.get(downloadId); switch (status) { case DownloadManager.STATUS_SUCCESSFUL: try { mPendingAutoOpenDownloads.remove(downloadId); if (OMADownloadHandler.OMA_DOWNLOAD_DESCRIPTOR_MIME.equalsIgnoreCase(info.getMimeType())) { mOMADownloadHandler.handleOMADownload(info, downloadId); manager.remove(downloadId); break; } Uri uri = manager.getUriForDownloadedFile(downloadId); Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(downloadId)); launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(launchIntent); } catch (ActivityNotFoundException e) { Log.w(TAG, "Activity not found."); } break; case DownloadManager.STATUS_FAILED: mPendingAutoOpenDownloads.remove(downloadId); break; default: break; } } } if (mPendingAutoOpenDownloads.size() == 0) { mContext.unregisterReceiver(this); } }