當前位置: 首頁>>代碼示例>>Java>>正文


Java DownloadManager.enqueue方法代碼示例

本文整理匯總了Java中android.app.DownloadManager.enqueue方法的典型用法代碼示例。如果您正苦於以下問題:Java DownloadManager.enqueue方法的具體用法?Java DownloadManager.enqueue怎麽用?Java DownloadManager.enqueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.DownloadManager的用法示例。


在下文中一共展示了DownloadManager.enqueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: downloadvideo

import android.app.DownloadManager; //導入方法依賴的package包/類
public void downloadvideo(String pathvideo)
{
    if(pathvideo.contains(".mp4"))
    {
        File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"Facebook Videos");
        directory.mkdirs();
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(pathvideo));
        int Number=pref.getFileName();
        request.allowScanningByMediaScanner();
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        File root = new File(Environment.getExternalStorageDirectory() + File.separator+"Facebook Videos");
        Uri path = Uri.withAppendedPath(Uri.fromFile(root), "Video-"+Number+".mp4");
        request.setDestinationUri(path);
        DownloadManager dm = (DownloadManager)getActivity().getSystemService(getActivity().DOWNLOAD_SERVICE);
        if(downloadlist.contains(pathvideo))
        {
            Toast.makeText(getActivity().getApplicationContext(),"The Video is Already Downloading",Toast.LENGTH_LONG).show();
        }
        else
        {
            downloadlist.add(pathvideo);
            dm.enqueue(request);
            Toast.makeText(getActivity().getApplicationContext(),"Downloading Video-"+Number+".mp4",Toast.LENGTH_LONG).show();
            Number++;
            pref.setFileName(Number);
        }

    }
}
 
開發者ID:adarshgumashta,項目名稱:Facebook-Video-Downloader,代碼行數:31,代碼來源:HomeFragment.java

示例2: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
/**
 * 開始下載APK
 */
private void startDownload(String downUrl) {
    Log.i(TAG, "startDownload: ");
    //獲得係統下載器
    mManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    //設置下載地址
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downUrl));
    // 設置允許使用的網絡類型,這裏是移動網絡和wifi都可以
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
    request.setAllowedOverRoaming(false);
    //設置可以被掃描到
    request.allowScanningByMediaScanner();
    //設置下載文件的類型
    request.setMimeType("application/vnd.android.package-archive");
    // 顯示下載界麵
    request.setVisibleInDownloadsUi(true);
    //設置下載存放的文件夾和文件名字
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkName);
    //設置下載時,通知欄是否顯示
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
    //設置標題
    request.setTitle(apkName.split("_")[0]);
    //執行下載,並返回任務唯一id
    enqueue = mManager.enqueue(request);
}
 
開發者ID:Jusenr,項目名稱:AppFirCloud,代碼行數:28,代碼來源:DownLoadService.java

示例3: downloadVideo

import android.app.DownloadManager; //導入方法依賴的package包/類
public static long downloadVideo(Context context, String url) {
    if (ContextCompat.checkSelfPermission(context,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        EventBus.getDefault().post(new EventPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE));
        return -1;
    }
    DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    if (url != null) {
        Uri uri = Uri.parse(url);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        File dst = FileUtils.createVideoFile(uri);
        if (dst.exists()) {
            Toast.makeText(context, R.string.video_exist, Toast.LENGTH_SHORT).show();
        } else {
            request.setDestinationUri(Uri.fromFile(dst));
            request.allowScanningByMediaScanner();
            long id = manager.enqueue(request);
            Log.d("download id", "-->" + id);
            return id;
        }
    }
    return -1;
}
 
開發者ID:mingdroid,項目名稱:tumbviewer,代碼行數:24,代碼來源:SystemDownload.java

示例4: download

import android.app.DownloadManager; //導入方法依賴的package包/類
private static void download(Context context, String url, File saveDirectory, String fileName) {
    File file = new File(saveDirectory, fileName);

    XposedBridge.log("[SoundCloud Downloader] Download path: " + file.getPath());

    if (file.exists()) {
        Toast.makeText(context, "File already exists!", Toast.LENGTH_SHORT).show();
        return;
    }

    DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(fileName);
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationUri(Uri.fromFile(file));

    try {
        downloadManager.enqueue(request);
        Toast.makeText(context, "Downloading...", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        XposedBridge.log("[SoundCloud Downloader] Download Error: " + e.getMessage());
        Toast.makeText(context, "Download failed!", Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:skyguy126,項目名稱:Xposed-SoundCloudDownloader,代碼行數:26,代碼來源:XposedMod.java

示例5: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
private void startDownload(String downloadUrl) {
    String apkUrl = Constants.setAliyunImageUrl(downloadUrl);
    String[] arr = apkUrl.split("/");
    apkName = arr[arr.length - 1];
    DownloadManager downloadManager = (DownloadManager) App.getDefault().getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(apkUrl));
    try {
        FileUtil.createFolder(downloadPath);
    } catch (Exception e) {
        e.printStackTrace();
    }
    request.setDestinationInExternalPublicDir("newVoice", apkName);
    String title = this.getResources().getString(R.string.app_name);
    request.setTitle(title);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    downloadManager.enqueue(request);
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:19,代碼來源:VersionUpdateService.java

示例6: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
private void startDownload() {
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "ency.apk");
    AppFileUtil.delFile(file, true);
    // 創建下載任務
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://ucdl.25pp.com/fs08/2017/09/19/10/2_b51f7cae8d7abbd3aaf323a431826420.apk?sf=9946816&vh=1e3a8680ee88002bdf2f00f715146e16&sh=10&cc=3646561943&appid=7060083&packageid=400525966&md5=27456638a0e6615fb5153a7a96c901bf&apprd=7060083&pkg=com.taptap&vcode=311&fname=TapTap&pos=detail-ndownload-com.taptap"));
    // 顯示下載信息
    request.setTitle("Ency");
    request.setDescription("新版本下載中");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
    request.setMimeType("application/vnd.android.package-archive");
    // 設置下載路徑
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "ency.apk");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    // 獲取DownloadManager
    dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    // 將下載請求加入下載隊列,加入下載隊列後會給該任務返回一個long型的id,通過該id可以取消任務,重啟任務、獲取下載的文件等等
    downloadId = dm.enqueue(request);
    Toast.makeText(this, "後台下載中,請稍候...", Toast.LENGTH_SHORT).show();
}
 
開發者ID:xiarunhao123,項目名稱:Ency,代碼行數:23,代碼來源:UpdateService.java

示例7: Downloading

import android.app.DownloadManager; //導入方法依賴的package包/類
public  static void Downloading(Context context , String url , String  title , String ext){
    String cutTitle = title;
    cutTitle = cutTitle.replace(" ", "-").replace(".", "-") + ext;
    downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setTitle(title);
    request.setDescription("Downloading");
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    String folderName = DOWNLOAD_DIRECTORY;
    SharedPreferences preferences = context.getSharedPreferences(PREF_APPNAME, Context.MODE_PRIVATE);

    if(!preferences.getString("path","DEFAULT").equals("DEFAULT")){


          mBaseFolderPath = preferences.getString("path","DEFAULT");
    }else{


         mBaseFolderPath=android.os.Environment.getExternalStorageDirectory()+ File.separator+folderName;
    }
    String[] bits = mBaseFolderPath.split("/");
    String Dir = bits[bits.length-1];
  //  request.setDestinationUri(new File(mBaseFolderPath).);
    request.setDestinationInExternalPublicDir(Dir, cutTitle);
    request.allowScanningByMediaScanner();
    downloadID = downloadManager.enqueue(request);

    iUtils.ShowToast(context,"Downloading Start!");
    //        // For interstitials
    if(AppLovinInterstitialAd.isAdReadyToDisplay(context)){
        // An ad is available to display.  It's safe to call show.
        AppLovinInterstitialAd.show(context);
        Log.d("APPLOVIN ADS Ready=====>","YES");
    }
    else{
        // No ad is available to display.  Perform failover logic...
        Log.d("Not Ready=====>","YES");

    }
}
 
開發者ID:zzzmobile,項目名稱:VideoDownloader-Android,代碼行數:41,代碼來源:DownloadFile.java

示例8: startDownload

import android.app.DownloadManager; //導入方法依賴的package包/類
private void startDownload() {
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(
            Uri.parse(MyApis.APK_DOWNLOAD_URL));
    request.setTitle("GeekNews");
    request.setDescription("新版本下載中");
    request.setMimeType("application/vnd.android.package-archive");
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "geeknews.apk");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    dm.enqueue(request);
    ToastUtil.shortShow("後台下載中,請稍候...");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:UpdateService.java

示例9: DownloadData

import android.app.DownloadManager; //導入方法依賴的package包/類
private long DownloadData (Uri uri) {

        long downloadReference;
        DownloadManager downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setTitle(tags.get(0)+getResources().getString(R.string.down));
        request.setDescription(getResources().getString(R.string.down_canvas));
        request.setDestinationInExternalPublicDir("/"+getResources().getString(R.string.app_name),hit.getId()+getResources().getString(R.string.jpg));
        downloadReference = downloadManager.enqueue(request);
        getContentResolver().insert(CanvasDownloadTable.CONTENT_URI,CanvasDownloadTable.getContentValues(hit,false));
        getContentResolver().notifyChange(CanvasDownloadTable.CONTENT_URI, null);

        return downloadReference;
    }
 
開發者ID:MuditSrivastava,項目名稱:Canvas-Vision,代碼行數:15,代碼來源:PicDetail.java

示例10: download

import android.app.DownloadManager; //導入方法依賴的package包/類
private void download() {
    if (!AppPerms.hasWriteStoragePermision(getActivity())) {
        AppPerms.requestWriteStoragePermission(getActivity());
        return;
    }

    DownloadManager.Request req = new DownloadManager.Request(Uri.parse(document.getUrl()));
    req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, document.getTitle());
    req.allowScanningByMediaScanner();
    req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    DownloadManager dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
    dm.enqueue(req);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:14,代碼來源:DocPreviewFragment.java

示例11: downloadImpl

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downloadImpl(){
    Document document = mDocuments.get(mCurrentIndex);

    DownloadManager.Request req = new DownloadManager.Request(Uri.parse(document.getUrl()));
    req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, document.getTitle());
    req.allowScanningByMediaScanner();
    req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    DownloadManager dm = (DownloadManager) App.getInstance().getSystemService(Context.DOWNLOAD_SERVICE);
    dm.enqueue(req);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:11,代碼來源:GifPagerPresenter.java

示例12: downloadImage

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downloadImage(String url, PhotoFragment.ActionType actionType) {
    if (null == getActivity()) return;
    String filename = mPhotos.id + "_" + mPhotos.user.name + PixelsApplication.DOWNLOAD_PHOTO_FORMAT;
    mDownloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url))
            .setTitle(filename)
            .setDestinationInExternalPublicDir(PixelsApplication.DOWNLOAD_PATH, filename)
            .setVisibleInDownloadsUi(false)
            .setNotificationVisibility(actionType == PhotoFragment.ActionType.DOWNLOAD ? DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED : DownloadManager.Request.VISIBILITY_VISIBLE);

    request.allowScanningByMediaScanner();
    downloadReference = mDownloadManager.enqueue(request);
}
 
開發者ID:alphater,項目名稱:garras,代碼行數:14,代碼來源:PhotoFragment.java

示例13: downloadFile

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downloadFile(String fileurl) {
    filePath = "/sdcard/Download/" + fileurl.substring(fileurl.lastIndexOf("/") + 1);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileurl));
    request.setDestinationInExternalPublicDir("/Download/", fileurl.substring(fileurl.lastIndexOf("/") + 1));
    mDownloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    mTaskId = mDownloadManager.enqueue(request);
    registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:9,代碼來源:DownloadService.java

示例14: downLoadApk

import android.app.DownloadManager; //導入方法依賴的package包/類
private void downLoadApk(FirAppInfo appInfo) {
    downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(appInfo.getAppDirectInstallUrl()));
    request.setDestinationInExternalFilesDir(activity, Environment.DIRECTORY_DOWNLOADS, "update.apk");
    request.setTitle(appInfo.getAppName());
    request.setDescription(appInfo.getAppVersionShort());
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setVisibleInDownloadsUi(false);
    request.setMimeType("application/cn.trinea.download.file");
    downloadId = downloadManager.enqueue(request);
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:12,代碼來源:FirUpdater.java

示例15: downloadWithSystemManager

import android.app.DownloadManager; //導入方法依賴的package包/類
@ProtoMethod(description = "Downloads a file from a given Uri. Returns the progress", example = "")
public void downloadWithSystemManager(String url, final ReturnInterface callback) {
    final DownloadManager dm = (DownloadManager) getContext().getSystemService(getContext().DOWNLOAD_SERVICE);
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    final long enqueue = dm.enqueue(request);

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(enqueue);
                Cursor c = dm.query(query);
                if (c.moveToFirst()) {
                    int columnIndex = c
                            .getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        if (callback != null) callback.event(null);
                        // callback successful
                    }
                }
            }
        }
    };

    getContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));


}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:32,代碼來源:PNetwork.java


注:本文中的android.app.DownloadManager.enqueue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。