当前位置: 首页>>代码示例>>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;未经允许,请勿转载。