我想從一個url下載一個二進制文件。是否可以使用我在這裏找到的Android下載管理器類DownloadManager class?Android:如何使用下載管理器類?
回答
是否有可能使用Android的下載管理器類,我發現這裏
是的,雖然這僅僅是由於Android API 9級(2.3版本)提供。 Here is a sample project演示使用DownloadManager
。
@ CommonsWare..I通過你的所有代碼。所有都是偉大的去了。 我想利用DownloadManager與wifi手段..我必須使用SFTP和從路由器下載文件..這是可能的嗎? 將請你指導我.. – NovusMobile 2012-06-07 12:55:37
@Satyam:'DownloadManager'不支持SFTP。 Android中沒有任何內容支持SFTP AFAIK。您需要爲此找到第三方JAR。 – CommonsWare 2012-06-07 12:58:16
我發現我在java名稱「JSCH」中使用的API。 @ CommonsWare在我的Java項目中,它的運行完美,但在這裏,Android不是.. 是否有可能? 或者我可能面臨其他問題? 請回復.. – NovusMobile 2012-06-07 13:05:45
使用下載管理器類(薑餅,只有更新版本)
薑餅帶來了新的功能,下載管理器,它可以讓你輕鬆下載文件,並委託處理線程的辛勤工作,溪流等系統。
首先,讓我們來看看一個實用方法:
/**
* @param context used to check the device version and DownloadManager information
* @return true if the download manager is available
*/
public static boolean isDownloadManagerAvailable(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
return true;
}
return false;
}
方法的名稱解釋這一切。一旦確定下載管理器是可用的,你可以做這樣的事情:
String url = "url you want to download";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Some descrition");
request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "name-of-the-file.ext");
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
下載進度將在通知欄展示。
DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("http://www.example.com/myfile.mp3");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle("My File");
request.setDescription("Downloading");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationUri(Uri.parse("file://" + folderName + "/myfile.mp3"));
downloadmanager.enqueue(request);
- 1. 如何啓動Android下載管理器
- 2. Android:下載管理器
- 3. 下載管理器Android:下載完成
- 4. 如何在Android中使用HttpClient創建下載管理器?
- 5. 我們如何使用Android下載管理器和RecyclerView?
- 6. 如何在Android上使用內置下載管理器
- 7. 如何使用下載管理器在Android的
- 8. 如何使用下載管理器,即使應用有背景
- 9. Android HTTP POST下載管理器
- 10. Android的下載管理器限制
- 11. Android的下載管理
- 12. 使用android下載管理器下載文件的網絡視圖
- 13. 如何從Android下載管理器完成所有下載後通知
- 14. 如何使用Android下載管理器將文件保存在SD卡上?
- 15. Android的下載管理器查詢下載
- 16. 下載文件,下載管理器的Android
- 17. Android通過改進VS下載管理器下載
- 18. Android讓下載管理器一次下載一個文件?
- 19. Android - 下載管理器 - 清除隊列中舊的下載
- 20. 通過Android下載管理器下載大文件
- 21. Android的下載管理器下載完成
- 22. Android的下載管理器說無法打開文件下載
- 23. Android的下載管理器下載位置
- 24. 實現下載管理器
- 25. 下載管理器VS InputStream.read()
- 26. 下載管理器概念
- 27. Xamarin.iOS下載管理器
- 28. 如何在android studio的sdk管理器上下載舊包(android 5.0)2.3.3
- 29. 下載沒有Android SDK管理器的Android SDK組件
- 30. 如何使'如果我按下按鈕,下載管理器打開'?
退房本教程http://www.gadgetsaint.com/android/download-manager/ – ASP 2017-05-23 12:52:50