我是Android的新手,我正在开发一个从给定网址下载文件的项目,它适用于mp3,但无法下载视频文件,如果下载的话还没有打开.... plz help 我的代码是这样的:
public class MainActivity extends AppCompatActivity {
String myUrl = "my url";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadManager.Request request=new
DownloadManager.Request(Uri.parse(myUrl));
request.setTitle("download");
request.setDescription("your file is downloading ...");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(MainActivity.this, Environment.DIRECTORY_DOWNLOADS,"testing.mp4");
DownloadManager manager =(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
答案 0 :(得分:0)
添加以下行:
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)