0
votes

I try to download a file through the browser. it's working perfectly if a have that :


    String pdfUrl = "www.myLink.com/document/test.pdf";
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(pdfUrl)); 
    startActivity(intent);

However if the link is :


    String pdfUrl = "www.myLink.com/document/test/";

It's very odd because it works on my browser "Chrome". I can download the 2 files....

1
Can you fin any solution for this? - Abdulmoiz Esmail

1 Answers

0
votes

Using the URL without the full file name will not work, because the Intent system does not know the type of the resource behind the URI - it will probably launch a browser pointed to that address instead of a PDF viewer. What you could do, however, is explicitly specify the content type behind your URL by using intent.setDataAndType() instead of intent.setData(), like this:

String pdfUrl = "www.myLink.com/document/test/";
Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(Uri.parse(pdfUrl), "application/pdf");

startActivity(intent);