Google Play에서 배경에 apk 파일을 설치하는 것처럼 백그라운드에서 URL에서 비디오를 다운로드하고 싶습니다. 알림 표시 줄에 다운로드 표시기를 표시하려면 APK 파일을 다운로드하거나 설치하는 동안 표시되는 것과 같습니다. 어떤 제안이나 아이디어가 내 프로젝트에서이 작업을 어떻게 성취 할 수 있는지 제안합니다.Google Play에서 apk 파일을 다운로드하거나 설치하는 것과 같이 내 애플리케이션에서 비디오를 다운로드하는 방법은 무엇입니까?
0
A
답변
2
android DownLoadManager을 선호 할 수 있습니다. 또한 다운로드 진행 알림 표시 줄 (창)에서> 쇼 다운로드 알림 -
어떻게 든 당신의 활동에 다음과 같이
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()
하고 싶어.
다음은 다운로드 한 파일 경로의 대상을 선택할 수있는 세 가지 방법입니다. getExternalFilesDir (문자열)에 의해 반환
는 (응용 프로그램의 외부 파일 디렉토리에있는 경로에 다운로드 한 파일의 로컬 대상을 설정합니다.
2. setDestinationInExternalPublicDir(String dirType, String subPath)
는 대한 로컬 대상을 설정 (getExternalStoragePublicDirectory (문자열)에 의해 반환)
3. setDestinationUri(Uri uri)
. 대중 외부 저장 디렉토리에 경로에 파일을 다운로드 다운로드 한 파일의 로컬 대상을 설정합니다.
0
다운로드 관리자를 사용하여
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;
}
어디에서 비디오를 저장합니까? 어떻게 폴더 이름을 추가 할 수 있습니까? –