我不知道为什么程序崩溃了。请引导我
为什么我的代码不起作用?
请帮助我
谢谢。
主要活动是:
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);
}
}
});
}}
表现形式是:
<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"/>