I have seen many tutorials for android download manager and every one is same.but promblem is that I have used this code in my app after using, but whenever I click this button my app is crashing. my version is android marshmallow and my code is here. also I want to ask I have three permissions in manifest of internet network and external storage. I also want to know that "is it possible to save download file in my app folders" if yes, how
public class Dashboard extends AppCompatActivity {
Button btn;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick (View view){
String url = "http://www.myweb.com/abc.png";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
// only download via WIFI
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setTitle("Example");
request.setDescription("Downloading a very large zip");
// we just want to download silently
request.setVisibleInDownloadsUi(false);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
request.setDestinationInExternalFilesDir(context, null, "large.zip");
// enqueue this request
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
long downloadID = downloadManager.enqueue(request);
}
});
}
}