I am trying to opening some pdf from my Android application. I am using an Intent for doing that:
Intent intent = new Intent(); intent.setDataAndType(Uri.parse(url), "application/pdf"); startActivity(intent);
This code works well for some pdf but it fails when I try to open others.
This is the message that Android is showing to me:
There is a problem with the file.
I have to mention that the pdf that are being opened without problems are created with one Crystal Report template and the pdfs that are failing are created with another one.
As opposed, if I open the url of the pdfs that are failing on my browser (on my computer), it does not give to me any error opening them so I guess that maybe there is some limitation on Android that differs from some pdf to another (on Crystal Report template) but I cannot see it.
What limitations exist on opening a pdf file on Android? (Size, some parameters of Crystal Report that are not allowed, etc...)
I have discarded that it could be a size limitation because the pdf files that are giving problems are smaller than the files that do not give any error.
1 Answers
Answers 1
It could be the file failed to be interpret by the Android PDF viewer app. Have you tried to copy/download the exact same file to your Android phone and open from there?
Also, I'd suggest to use IntentChooser for launching the PDF viewer, just to play safe on no PDF viewer installed / giving user option to choose app:
Intent intent = new Intent(); intent.setDataAndType(Uri.parse(url), "application/pdf"); Intent chooserIntent = Intent.createChooser(intent, "Open Report"); startActivity(chooserIntent);
0 comments:
Post a Comment