douarbou
douarbou

Reputation: 2283

Android : Download file without .pfd, .png... at end of the link

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....

Upvotes: 0

Views: 391

Answers (1)

olex
olex

Reputation: 797

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);

Upvotes: 0

Related Questions