Android DownloadManager.Request - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DownloadManager.Request class.

This code example shows how to use the following methods: enqueue, setDestinationInExternalPublicDir
 
        // Check whether we have permission to write file to external storage. 
        // We only start download request if we have permission. 
        if (!checkWriteExternalPermission()) return; 
 
        Request request = new Request(Uri.parse(url));
        request.setDestinationInExternalPublicDir(
                Environment.DIRECTORY_DOWNLOADS, fileName);
        getDownloadManager().enqueue(request);
        popupMessages(DOWNLOAD_START_TOAST + fileName);
    } 
 
    private String getFileName(String url, String contentDisposition, String mimetype) {
        String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
        int extensionIndex = fileName.lastIndexOf(".");
        String extension = null;
        if ((extensionIndex > 1) && (extensionIndex < fileName.length())) {
            extension = fileName.substring(extensionIndex + 1);
        } 
 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setDescription, setDestinationInExternalPublicDir, setNotificationVisibility, setShowRunningNotification, setTitle
  
        Environment  
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) 
            .mkdirs(); 
  
        Request req = new DownloadManager.Request(uri); 
  
        req.setTitle("Demo"); 
        req.setDescription("android-ndk-r6-linux-x86.tar.bz2"); 
        req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"android-ndk-r6-linux-x86.tar.bz2"); 
        req.setNotificationVisibility(0); 
        req.setShowRunningNotification(true); 
  
        lastDownload = mDownloadManager.enqueue(req);  
    }     
	 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setDescription, setDestinationInExternalPublicDir, setNotificationVisibility, setShowRunningNotification, setTitle
  
        Environment  
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) 
            .mkdirs(); 
  
        Request req = new DownloadManager.Request(uri); 
  
        req.setTitle("Demo"); 
        req.setDescription("android-ndk-r6-linux-x86.tar.bz2"); 
        req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"android-ndk-r6-linux-x86.tar.bz2"); 
        req.setNotificationVisibility(0); 
        req.setShowRunningNotification(true); 
  
        lastDownload = mDownloadManager.enqueue(req);  
    }     
	 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setDescription, setDestinationInExternalPublicDir, setMimeType, setTitle
		// MIME Type을 확장자를 통해 예측한다. 
		String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()).toLowerCase();
		String mimeType = mtm.getMimeTypeFromExtension(fileExtension);
 
		// Download 디렉토리에 저장하도록 요청을 작성 
		Request request = new DownloadManager.Request(downloadUri);
		request.setTitle(fileName);
		request.setDescription(url);
		request.setMimeType(mimeType);
		request.setDestinationInExternalPublicDir( "/Android/data/com.ssm.luaming/files/.Luaming/" + activity.accessToken + "/" + activity.packageName, activity.updateName);
 
		// 다운로드 매니저에 요청 등록 
		activity.downloadId = downloadManager.enqueue(request);
		 
		// Progress Dialog 
		activity.pd = new LuamingProgressDialog(activity);
		 
		LuamingDownloadTask downTask = new LuamingDownloadTask(activity);
		 
		activity.pd.setAsyncTask(downTask);
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setAllowedNetworkTypes, setDescription, setDestinationInExternalPublicDir, setVisibleInDownloadsUi
				 
				public void onDownloadStart(String url, String userAgent,
						String contentDisposition, String mimetype, long contentLength) {
					DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
					Uri uri = Uri.parse(url);  
				    Request request = new Request(uri);  
				    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE|DownloadManager.Request.NETWORK_WIFI);    
				    request.setVisibleInDownloadsUi(true);  
				   // request.setDestinationUri(Uri.parse("/mnt/sdcard/a.doc")); 
				    request.setDescription("电子书下载中");
				    request.setDestinationInExternalPublicDir("ebook",uri.getLastPathSegment());
				    downloadManager.enqueue(request);
				} 
			}); 
		return v;
	} 
 
	public boolean onBack() { 
		if(v!=null&&v.canGoBack()){
			v.goBack();
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: allowScanningByMediaScanner, setDestinationInExternalPublicDir, setVisibleInDownloadsUi
 
	public long download(Context context, String url) {
		// Download data.. 
		Uri uri = Uri.parse(url);
 
		DownloadManager.Request request = new Request(uri);
		/* 
		 * DownloadManager.Request对象request添加HTTP头,也可以通过setMimeType方法重写从服务器返回的mime 
		 * type 
		 */ 
		// request.addRequestHeader(arg0, arg1); 
		// 禁止发出通知,既后台下载 
		/*<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>*/ 
		// request.setShowRunningNotification(false); 
		//request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
		 
		//表示下载进行中和下载完成的通知栏是否显示。 
		//默认只显示下载中通知。VISIBILITY_VISIBLE_NOTIFY_COMPLETED表示下载完成后显示通知栏提示。 
		//VISIBILITY_HIDDEN表示不显示任何通知栏提示,这个需要在AndroidMainfest中添加权限 
		//request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setDescription, setDestinationInExternalPublicDir, setTitle
    Button startButton = (Button) findViewById(R.id.startdownload);
    // 开始下载 
    startButton.setOnClickListener(new OnClickListener() {
      @Override 
      public void onClick(View arg0) {
        DownloadManager.Request request = new Request(uri);
        referenceID = downloadManager.enqueue(request);
 
        // 设置下载存放路径 
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, "test_downloadmanager.zip");
 
        // 自定义Notification 
        request.setTitle("testdownload");
        request.setDescription("Test");
      } 
    }); 
 
    // 点击"Cancel"按钮取消正在下载的任务 
    Button cancelButton = (Button) findViewById(R.id.canceldownload);
    cancelButton.setOnClickListener(new OnClickListener() {
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setAllowedNetworkTypes, setDescription, setDestinationInExternalPublicDir, setTitle
		// (et le cree si il n'existe pas) 
		Environment.getExternalStoragePublicDirectory(
				Environment.DIRECTORY_DOWNLOADS).mkdirs();
 
		// On cree une requete de telechargement 
		Request dr = new DownloadManager.Request(uri);
		dr.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
				| DownloadManager.Request.NETWORK_MOBILE);
		dr.setTitle("Update facts");
		dr.setDescription("A updated version of the fact list for the Fact widget.");
		dr.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
				"factList");			 
		return dr;
	} 
 
	/** 
	 * Enregistre deux broadcast receiver pour le download completion 
	 */ 
	private void registerBroadcastReceivers() { 
		 
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setAllowedNetworkTypes, setDestinationInExternalPublicDir
This code example shows how to use the following methods: setDestinationUri, setNotificationVisibility
    { 
        if (!downloading.contains(item.getPathToSave()))
        { 
            downloading.add(item.getPathToSave());
            DownloadManager dm = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
            Request request = new Request(Uri.parse(item.getUrl()));
            File destFile = new File(item.getPathToSave());
            destFile.mkdirs();
            request.setDestinationUri(Uri.parse("file://" + item.getPathToSave()));
 
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
            { 
                request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
            } 
            else 
            { 
                request.setShowRunningNotification(false);
            } 
 
            if (destFile.exists())
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android DownloadManager.Request Questions & Answers:

See Code Examples for Android DownloadManager.Request Methods: