我正在尝试开发一款提供很多电影的应用,你可以播放或下载电影。
我正在使用下载管理器从服务器下载电影,但它无效......
这是我的方法
public void downloadFileFromUrl(String url, String fileName) {
String filePath=Environment.getExternalStorageDirectory() + File.separator + "BlueNet";
File folder = new File(filePath);
if (!folder.exists()) {
folder.mkdirs();
}
try {
Uri downloadUri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir("BlueNet", fileName);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setVisibleInDownloadsUi(true);
DownloadManager downloadManager = (DownloadManager)getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
long id= downloadManager.enqueue(request);
}
catch (Exception ex){
Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show();
}
}
这是属性
网址 :( http://192.168.1.5:8080/BlueNet_NMC/video_shared/blue_elephant.mp4)
文件名 :( blue_elephant.mp4)
我已将此权限授予舱单
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
但是当我在模拟器或我的Galaxy S4中测试时无法正常工作。
请帮帮我。