I'm using some code which I've found on YouTube as well as Stackoverflow to download a file from a website. This has been working fine, but now I would like to open the PDF which has been downloaded in a WebView. I will figure out how to do that, but first I need to know how to execute a function which is in a Fragment once the download has finished. I alread tried using a BroadcastReceiver but I guess I did it wrong :(
My Code:
private void downloadZusammenfassung(View v){
DownloadManager downloadManager;
downloadManager = (DownloadManager)getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
Button button = (Button)v;
String zusammenfassungLink = "https://dan6erbond.github.io/I1A/Documents/Zusammenfassungen/" + button.getText() + ".pdf";
Log.i("TAG", zusammenfassungLink);
Uri uri = Uri.parse(zusammenfassungLink);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
openZusammenfassung();
}
};
Intent registerReceiver (onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
}
public void openZusammenfassung(){
Log.i("TAG", "bla");
}