0

I don't know why the program crashed. please guide me

why is my code not working ?

please help me,

thank you.

Main Activity is:

            if (url.equals("")){
                Toast.makeText(MainActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
            }else {
                String nameFile=url.substring(url.lastIndexOf("/"));
                DownloadManager downloadManager= (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                request.setTitle("Download File");
                request.setDescription("دانلود");
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, nameFile);
                request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);


                downloadManager.enqueue(request);



            }
        }
    });
}}

manifestes is:


    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

enter image description here

amir
  • 1
  • 5

0 Answers0