I have tried to display a PDF file by using a WebView using the following code -
webview.loadUrl("http://www.mywebsite.co.uk/floorplan.pdf");
or
Uri uri = Uri.parse("http://www.mywebsite.co.uk/floorplan.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Using either I cannot get the PDF to display unless I run it through Adobe (so my app is downloading it), which then looks fine. How can I get the PDF to display using Adobe through my app or am I better off displaying the PDF as an image instead?
You'd have to build a pdf viewer to display it inside your app. Your best best is to launch the Intent like you are doing to display it in an external pdf viewer.
Check out this question for more.
Show PDF in Android
Related
I have and android app. It has a pdf in assets folder. I written a code to view this pdf in external app(like adobe pdf viewer). It is working fine but problem is that there is Share option in Adobe pdf viewer. I dont want that user can distribute this pdf.
My problem is that there is an important pdf book and I want user can read only but can not share or redistribute it. Please give an idea. I will change my code.
I am using following code:
Uri path = Uri.fromFile(new File(str,
"lemmelibroandroid.pdf"));
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(pdfIntent);
I dont think it is possible to limit the capabilities of the external application used to open the pdf
Have a look at
http://asmncl.blogspot.in/2012/06/android-open-pdf-file-in-webview.html to see how to open the pdf in a WebView
It is not possible,so the best option here will be to show your content in your own app.
I am sure that you will find a proper way to display it some how in activity.
Maybe you should change the format of PDF to HTML and it will be easier to show.
I have between one and three photos I'd like my app to display. I won't know until runtime exactly how many photos are downloaded from the Internet.
I can't figure out how to create an Intent to display the photos. Right now I'm caching them on the sdcard under a folder I create by doing something like (sans error checking):
final File externalDirectory = Environment.getExternalStorageDirectory();
final String folder = externalDirectory.getAbsolutePath() + "/Android/data/" + packageName + "/files/";
This was explained in the Android Developer Reference.
I can get one photo to display by doing the following:
final Uri uri = Uri.fromFile(file);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
Util.startActivity(this, intent);
Where file is the file of a saved photo.
If it helps, I could save the images to any location available to my app, however I would prefer to not have the photos show up listed with the user's other personal photos as that may be annoying.
The Image Viewer has a menu option "Slideshow", so it must know about multiple photos.
I could create my own Image Viewer, but that seems like extra work and beyond what I would I reasonably expect. Even if I did this, I would like the user to be able to install a 3rd party Image Viewer and get a better experience with pan, zoom, share, ...
I tried using the directory of the cached photo files to create the Uri, but the Image Viewer shows a black page. If I pass in the file, it shows just that one file and no others.
I know this must be possible because I can see use the Gallery app and show the photos if I manually select the folder. Everytime I research this issue, the comments say it's not possible to show multiple images.
I suspect there's some magic incantation, but what?
I think your goal is out of your control. If the viewer app is designed to handle mutiple images or a directory, you may ask it to show as you want, but you are defined to the viewer's pattern.
I have installed a third-party image viewer called QuickPic. I just tested your code snippet and the system popped up a chooser dialog to let me select the app to show the images in the folder. If I select native gallery, what I see is just an empty folder, while the Quickpic works as I want.
PS: I tell my app the Uri of the folder this way:
intent.setDataAndType(Uri.fromFile(new File("//mnt/sdcard/test/")), MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"));
I know this question has been asked several times but I couldnt find one satisfying answer.My requirement is simple.just to open the pdf docs within my app(android).But I am not able to find a simple way of doing this.either its native c/c++ way or writing your own engine.But isnt there any simple API so that I can include it like a jar and view the pdf?
No. There is no API in the Android SDK to natively display PDF.
Solutions I can suggest:
-Use an external application:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);
-If your PDF document is accessible online, use the Google Docs Viewer to open your PDF in a WebView:
http://docs.google.com/viewer?url=http://mypdf.pdf
you can use native plugin to show the PDF within your app. try this apv
Does android provide any built it control like video view or image view to display pdf ebook?
More specifically I want to open a pdf ebook in android with following controls on the screen.
zooming controls
turn over functionality/swipe to change page.
What is the suitable way to achieve this?
Android does not provide a default PDF reader. I believe some phones come with a pre-installed application for reading PDFs, but you cannot rely on this fact for all devices. The best you can do for now is choose to open the user's default PDF reader (if they have one installed).
Use an intent to open up the user's default PDF app (untested, should be something like this):
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(pathToPDF, "application/pdf");
startActivity(intent)
I want to show a pdf in my application. My webservice gives me the pdf and I want to download it to sd card and then I want show that pdf in my app through webview.
I was also struggling with Android PDF showing problem for some time. I did the same approach as you mentioned with downloading the PDF to the SD card, but I did not manage to open it up otherwise than using a preinstalled Android App which could do the PDF opening (e.g. Adobe Reader or similar). I think that it's not possible to view the PDF in a WebView widget. The reason is simply that the included webview does not support plugins like adobe reader (see: http://osdir.com/ml/Android-Developers/2010-09/msg03331.html)
You can easily open up the downloaded PDF using an Intent call:
File file = new File("/sdcard/filename.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Due to the fact that this technique opens up the PDF viewer directly after my application makes this call, the back button takes the user directly back to the app, so it feels like the pdf viewing is part of my app.
Hope this helps, best regards
As already answered here, the WebView can't render PDFs. You can do what it is said in the accepted answer in this question and try to open the PDF with the default PDF viewer in the device. If the device has no PDF viewer installed, a message will be displayed to the user.