-2

I am new to Android, am working on a project which downloads files from given url,it works fine for mp3 but am not able to download video files and if it is downloaded than it does not open....plz help my code is like this:

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);
}
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
Shahid Ali
  • 11
  • 4

1 Answers1

0

Add this line:

request.setAllowedNetworkTypes(DownloadManager.Request.NETWO‌​RK_WIFI | DownloadManager.Request.NETWORK_MOBILE)

Saurabh Thorat
  • 18,131
  • 5
  • 53
  • 70