-3
我是Android新手,正在從給定網址下載文件的項目中工作,它對mp3很好,但無法下載視頻文件,如果下載比不開放.... plz幫助 我的代碼是這樣的:在Android中使用DownloadManager下載視頻文件
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);
}
嘗試加入這一行:'request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |下載管理.Request.NETWORK_MOBILE)' –
@SaurabhThorat謝謝你這麼多先生,它開始工作,但我不知道它是如何開始工作的,增加了這條線? –
我會將其作爲回答發佈,以便對其他人有所幫助 –