I am trying to download a pdf file from my app.
I've tried two methods:
webView.loadUrl(uriPath);
webView.setDownloadListener(new DownloadListener()
{
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
and next
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(uriPath));
startActivity(i);
Both of these methods are using Intent.ACTION_VIEW
End of the day my file is downloaded but before downloading it is showing the web browser, loading the page, then coming back to my app, giving a Toast Downloading
I want to hide the browser, there are questions to hide the url on browser but not to hide the browser.
I found an unanswered question Here
Kindly suggest me how to do this task. Thank you.
Edit: Structure of my activity
public class Pdf extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
new Displays().execute();
}
private class Displays extends AsyncTask<String, Void, Void>
{
@Override
protected Void doInBackground(String... params)
{
//retrieving the list of pdf documents url.
}
@Override
protected void onPostExecute(Void aVoid)
{
text = new TextView(getApplicationContext());
text.setText(list1.get(i));
text.setOnClickListener(...)
{
//here download the selected pdf
//if am am calling any async class or any method from here file is not getting downloaded.What to do :(
}
}
}
}