Android 我如何在我的应用程序中下载视频,就像在google play上下载或安装apk文件一样?

Android 我如何在我的应用程序中下载视频,就像在google play上下载或安装apk文件一样?,android,download,android-videoview,Android,Download,Android Videoview,我想在后台从URL下载视频,就像从Google play在后台安装apk文件一样。我想在通知栏上显示下载指示器,就像我们下载或安装apk文件时显示的一样。如果有任何建议或想法,请建议我如何在我的项目中完成这项任务 你可以更喜欢安卓。在你的活动中想这样做 String mUrl="your video url"; DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); Request requ

我想在后台从URL下载视频,就像从Google play在后台安装apk文件一样。我想在通知栏上显示下载指示器,就像我们下载或安装apk文件时显示的一样。如果有任何建议或想法,请建议我如何在我的项目中完成这项任务

你可以更喜欢安卓。
在你的活动中想这样做

String mUrl="your video url";

DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(mUrl));
            request.setDestinationInExternalFilesDir(getApplicationContext(), Environment.DIRECTORY_DOWNLOADS, your_fileName);
            request.setNotificationVisibility(Request.VISIBILITY_VISIBLE);
            request.setAllowedOverRoaming(false);
            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
            manager.enqueue(request);

setNotificationVisibility()
->在通知栏(窗口)中显示下载通知以及下载进度。

下面是三种方法,您可以在其中为下载的文件路径选择目标。
1.
setDestinationNexternalFilesDir(上下文、字符串目录类型、字符串子路径)
将下载文件的本地目标设置为应用程序外部文件目录中的路径(由getExternalFilesDir(字符串)返回)


2.
setDestinationNexternalPublicDir(字符串目录类型,字符串子路径)
将下载文件的本地目标设置为公共外部存储目录中的路径(由getExternalStoragePublicDirectory(字符串)返回)


3.setDestinationUri(Uri)
设置下载文件的本地目标。

使用下载管理器

private void for_call_download() {
        File folder = Environment.getExternalStoragePublicDirectory(DOWNLOAD_FOLDER_NAME);
        if (!folder.exists() || !folder.isDirectory()) {
            folder.mkdirs();
        }
        try {
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(APK_URL));
            request.setDestinationInExternalPublicDir(DOWNLOAD_FOLDER_NAME, DOWNLOAD_FILE_NAME);
            request.setTitle(SessionName);
            request.setDescription("" + SessionDesc);
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setVisibleInDownloadsUi(false);
            request.setMimeType("application/cn.trinea.download.file");
            downloadId = downloadManager.enqueue(request);
        } catch (IllegalStateException i) {
            showAlert(context, "Sorry Some Problem");
            i.printStackTrace();
        }
        updateView();
        status_download = true;
    }

视频将保存在哪里?如何添加文件夹名称?