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:org.botlibre.sdk.activity.graphic.GraphicActivity.java
public void downloadFile(View v) { if (gInstance.fileName.equals("")) { MainActivity.showMessage("Missing file!", this); return;//from w w w . jav a 2s. c o m } String url = MainActivity.WEBSITE + "/" + gInstance.media; try { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(gInstance.fileName); request.setDescription(MainActivity.WEBSITE); // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); only download thro wifi. request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); Toast.makeText(GraphicActivity.this, "Downloading " + gInstance.fileName, Toast.LENGTH_SHORT).show(); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, gInstance.fileName); DownloadManager manager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE); BroadcastReceiver onComplete = new BroadcastReceiver() { public void onReceive(Context ctxt, Intent intent) { Toast.makeText(GraphicActivity.this, gInstance.fileName + " Downloaded!", Toast.LENGTH_SHORT) .show(); } }; manager.enqueue(request); registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } catch (Exception e) { MainActivity.showMessage(e.getMessage(), this); } }
From source file:com.github.notizklotz.derbunddownloader.download.IssueDownloadService.java
@ServiceAction public void downloadIssue(int day, int month, int year) { Log.i(LOG_TAG, "Handling download intent"); try {/*from w w w. j a v a 2 s. com*/ boolean connected; final boolean wifiOnly = Settings.isWifiOnly(getApplicationContext()); if (wifiOnly) { connected = waitForWifiConnection(); if (!connected) { notifyUser(getText(R.string.download_wifi_connection_failed), getText(R.string.download_wifi_connection_failed_text), R.drawable.ic_stat_newspaper); } } else { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); connected = activeNetworkInfo != null && activeNetworkInfo.isConnected(); if (!connected) { notifyUser(getText(R.string.download_connection_failed), getText(R.string.download_connection_failed_text), R.drawable.ic_stat_newspaper); } } if (connected) { if (!checkUserAccount()) { notifyUser(getText(R.string.download_login_failed), getText(R.string.download_login_failed_text), R.drawable.ic_stat_newspaper); } else { final LocalDate issueDate = new LocalDate(day, month, year); fetchThumbnail(issueDate); final CountDownLatch downloadDoneSignal = new CountDownLatch(1); receiver = new DownloadCompletedBroadcastReceiver(downloadDoneSignal); registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); try { String title = startDownload(issueDate, wifiOnly); downloadDoneSignal.await(); notifyUser(title, getString(R.string.download_completed), R.drawable.ic_stat_newspaper); } catch (InterruptedException e) { Log.wtf(LOG_TAG, "Interrupted while waiting for the downloadDoneSignal"); } } } } catch (Exception e) { notifyUser(getText(R.string.download_service_error), getText(R.string.download_service_error_text) + " " + e.getMessage(), R.drawable.ic_stat_newspaper); } finally { cleanup(); } }
From source file:com.stoneapp.ourvlemoodle2.fragments.CourseContentFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Context context = getActivity(); rootView = inflater.inflate(R.layout.frag_course_content, container, false); txt_notpresent = (TextView) rootView.findViewById(R.id.txt_notpresent); img_notpresent = (ImageView) rootView.findViewById(R.id.no_content); mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swiperefresh); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBarContent); contentList = (RecyclerView) rootView.findViewById(R.id.coursecontent_listview); //List<MoodleSiteInfo> sites = MoodleSiteInfo.listAll(MoodleSiteInfo.class); //retrieves site info course = MoodleCourse.find(MoodleCourse.class, "courseid = ?", courseid + "").get(0); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary, R.color.colorPrimaryDark);/*from w ww . j av a 2 s . c o m*/ mSwipeRefreshLayout.setOnRefreshListener(this); // String name = sites.get(0).getFirstname().charAt(0)+sites.get(0).getLastname(); ContentSync csync = new ContentSync(courseid, coursepid, siteid, token, context); progressBar.setIndeterminate(true); progressBar.setVisibility(View.GONE); sections = csync.getContents(); // sync content sectionsToListItems(sections); // adds content to list items contentList.setHasFixedSize(true); contentList.setLayoutManager(new LinearLayoutManager(getActivity())); cadapter = new CourseContentListAdapter(getActivity(), items, token, courseid, course.getShortname(), this); contentList.setAdapter(cadapter); //checks if any content is present if (items.size() > 0) { img_notpresent.setVisibility(View.GONE); txt_notpresent.setVisibility(View.GONE); } //register download completion receiver getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); ConnectivityManager connectivityManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connectivityManager.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.isConnected()) //refreshes content new LoadContentTask(courseid, coursepid, siteid, context).execute(""); return rootView; }
From source file:dentex.youtube.downloader.UpgradeApkActivity.java
@Override protected void onStart() { super.onStart(); registerReceiver(apkReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); Log.v(DEBUG_TAG, "_onStart"); }
From source file:de.nico.asura.Main.java
@Override protected void onResume() { super.onResume(); IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); registerReceiver(downloadReceiver, intentFilter); }
From source file:org.apache.cordova.backgroundDownload.BackgroundDownload.java
private void startAsync(JSONArray args, CallbackContext callbackContext) throws JSONException { if (activDownloads.size() == 0) { // required to receive notification when download is completed Log.d("BackgroundDownload", "Registering the receiver"); cordova.getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }/*w ww . jav a 2 s . c o m*/ Download curDownload = new Download(args.get(0).toString(), args.get(1).toString(), callbackContext); if (activDownloads.containsKey(curDownload.getUriString())) { if (args.length() >= 4) { boolean resumeCurrent = args.getBoolean(3); if (resumeCurrent) { StartProgressTracking(curDownload); return; } } else { return; } } activDownloads.put(curDownload.getUriString(), curDownload); curDownload.setDownloadId(findActiveDownload(curDownload.getUriString())); if (curDownload.getDownloadId() == DOWNLOAD_ID_UNDEFINED) { // make sure file does not exist, in other case DownloadManager will fail File targetFile = new File(Uri.parse(curDownload.getTempFilePath()).getPath()); targetFile.delete(); DownloadManager mgr = (DownloadManager) this.cordova.getActivity() .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(curDownload.getUriString())); // Use the cookie from the webview, so the session cookie is shared request.addRequestHeader("Cookie", this.webView.getCookieManager().getCookie(curDownload.getUriString())); try { // Get the app label and set it as the title int appLabelResId = this.webView.getContext().getApplicationInfo().labelRes; request.setTitle(this.webView.getContext().getString(appLabelResId)); } catch (Resources.NotFoundException e) { // Use generic title if the app label wasn't found request.setTitle("Background download plugin"); } request.setVisibleInDownloadsUi(false); // if (Build.VERSION.SDK_INT >= 11) { // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); // } request.setDestinationUri(Uri.parse(curDownload.getTempFilePath())); Log.d("BackgroundDownload", "downloading"); curDownload.setDownloadId(mgr.enqueue(request)); } else if (checkDownloadCompleted(curDownload.getDownloadId())) { callbackContext.success(); } StartProgressTracking(curDownload); }
From source file:com.laquysoft.droidconnl.Hunt.java
/** Generates the entire hunt structure from JSON */ Hunt(String jsonString, Resources res, Context context) { //set filter to only when download is complete and register broadcast receiver IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); context.registerReceiver(downloadReceiver, filter); soundManager = new SoundManager(context); achievementManager = new AchievementManager(res); try {// w w w. j a v a2s .c om clues = new HashMap<String, Clue>(); clueList = new ArrayList<Clue>(); tags = new HashMap<String, AHTag>(); JSONObject huntObject = new JSONObject(jsonString); JSONArray clueObjList = huntObject.getJSONArray("clues"); tagList = new ArrayList<AHTag>(); int length = clueObjList.length(); for (int i = 0; i < length; i++) { JSONObject clueObj = clueObjList.getJSONObject(i); Clue clue = new Clue(clueObj.getString("id"), clueObj.getString("displayName"), clueObj.getString("displayText"), clueObj.getString("displayImage")); clue.shufflegroup = clueObj.getInt("shufflegroup"); JSONArray tagObjList = clueObj.getJSONArray("tags"); int tagLength = tagObjList.length(); clueList.add(clue); for (int j = 0; j < tagLength; j++) { JSONObject tagObj = tagObjList.getJSONObject(j); AHTag tag = new AHTag(tagObj.getString("id")); tag.clueId = clue.id; clue.addTag(tag); tags.put(tag.id, tag); tagList.add(tag); } if (clueObj.has("question")) { clue.question = new TriviaQuestion(clueObj.getJSONObject("question")); } } } catch (Exception e) { if (e != null) Log.e("JSON Parser", "Error parsing Hunt data " + e.toString()); } reset(); restore(res, context); }
From source file:org.catrobat.catroid.ui.WebViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); ActionBar actionBar = getActionBar(); actionBar.hide();/*w ww . j a v a 2s .com*/ Intent intent = getIntent(); url = intent.getStringExtra(INTENT_PARAMETER_URL); if (url == null) { url = Constants.BASE_URL_HTTPS; } callingActivity = intent.getStringExtra(CALLING_ACTIVITY); webView = (WebView) findViewById(R.id.webView); webView.setBackgroundColor( ResourcesCompat.getColor(getResources(), R.color.application_background_color, null)); webView.setWebViewClient(new MyWebViewClient()); webView.getSettings().setJavaScriptEnabled(true); String language = String.valueOf(Constants.CURRENT_CATROBAT_LANGUAGE_VERSION); String flavor = Constants.FLAVOR_DEFAULT; String version = Utils.getVersionName(getApplicationContext()); String platform = Constants.PLATFORM_DEFAULT; webView.getSettings().setUserAgentString( "Catrobat/" + language + " " + flavor + "/" + version + " Platform/" + platform); webView.loadUrl(url); webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Log.d(WebViewActivity.class.getSimpleName(), "contentDisposition: " + contentDisposition + " " + mimetype); if (getExtensionFromContentDisposition(contentDisposition).contains(Constants.CATROBAT_EXTENSION)) { DownloadUtil.getInstance().prepareDownloadAndStartIfPossible(WebViewActivity.this, url); } else if (url.contains(Constants.LIBRARY_BASE_URL)) { String name = getMediaNameFromUrl(url); String mediaType = getMediaTypeFromContentDisposition(contentDisposition); String fileName = name + getExtensionFromContentDisposition(contentDisposition); String tempPath = null; switch (mediaType) { case Constants.MEDIA_TYPE_LOOK: tempPath = Constants.TMP_LOOKS_PATH; break; case Constants.MEDIA_TYPE_SOUND: tempPath = Constants.TMP_SOUNDS_PATH; } String filePath = Utils.buildPath(tempPath, fileName); resultIntent.putExtra(MEDIA_FILE_PATH, filePath); DownloadUtil.getInstance().prepareMediaDownloadAndStartIfPossible(WebViewActivity.this, url, mediaType, name, filePath, callingActivity); } else { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(getString(R.string.notification_download_title_pending) + " " + DownloadUtil.getInstance().getProjectNameFromUrl(url)); request.setDescription(getString(R.string.notification_download_pending)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, DownloadUtil.getInstance().getProjectNameFromUrl(url) + ANDROID_APPLICATION_EXTENSION); request.setMimeType(mimetype); registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); downloadManager.enqueue(request); } } }); }
From source file:com.fairphone.updater.UpdaterService.java
private void setupDownloadManager() { mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); mDownloadBroadCastReceiver = new DownloadBroadCastReceiver(); getApplicationContext().registerReceiver(mDownloadBroadCastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
From source file:org.wso2.app.catalog.api.ApplicationManager.java
/** * Installs an application to the device. * * @param url - APK Url should be passed in as a String. *///from w w w . j ava 2 s. c om public void installApp(String url) { if (isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) { CommonUtils.callAgentApp(context, Constants.Operation.INSTALL_APPLICATION, url, null); } else if (isDownloadManagerAvailable(context)) { IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); context.registerReceiver(downloadReceiver, filter); downloadViaDownloadManager(url, downloadedAppName); } else { AppUpdater updater = new AppUpdater(); updater.execute(url); } }