I know there are many similar questions, but I need specifics. I originally wanted my app to open PDFS within the app itself, but I have settled to send an intent activity to adobe reader. I am currently opening PDFS by looking for the file on the device itself. Is there a way I can have the PDFS in my app, and create a folder on the users device, and then look for them? or something similar? Obvisouly the user isn't going to have the PDF already installed on their device. Here is my current code.
Intent intent7 = new Intent();
intent7.setPackage("com.adobe.reader");
intent7.setDataAndType(Uri.fromFile(new File("/storage/emulated/0/Download/Auto-example.pdf")), "application/pdf");
startActivity(intent7);
Is there a way I can have the PDFS in my app, and create a folder on the users device, and then look for them?
You can put the PDF in internal storage (e.g., getFilesDir()), then use FileProvider to serve them via a ContentProvider. This sample project demonstrates serving a PDF from internal storage (copied there from assets/) and viewing it in the user's chosen PDF viewer. There is also an Android training module covering this.
With respect to the code that you have, please use ACTION_VIEW as your Intent action (e.g., pass that to the constructor) and delete the setPackage() line.
Related
I am looking to create an app that has a brief detail about a product, then on the click of the button on that app page it takes you to a detailed brochure or manual stored on the sd card.
need an intent to open a pdf from the sd card
ideally the same intent, but different file locations defined with the associated button.
I can get a button to do something onclick, but don't know how to do the open the pdf file from sd card using adobe reader.
I would be grateful for a solution, or a link to a tutorial so I progress, but everything I have read doesn't quite fit. In the meantime I will keep searching.
Thanks
I am looking to create an app that has a brief detail about a product, then on the click of the button on that app page it takes you to a detailed brochure or manual stored on the sd card.
Since you do not have much access to removable storage, I sincerely hope that by "sd card", you mean external storage.
need an intent to open a pdf from the sd card
Use:
new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(filePointingToYourPdf), "application/pdf");
with startActivity().
but don't know how to do the open the pdf file from sd card using adobe reader.
Since the user does not necessarily have "adobe reader", just call startActivity() with the aforementioned Intent, where filePointingToYourPdf is a File object pointing to the PDF to view.
but everything I have read doesn't quite fit
In the future, when using Stack Overflow, please explain what you tried and why it "doesn't quite fit". We cannot help you with that if you do not tell us what it is.
I am working on app that has to open a pdf file in an external pdf application. It works fine, the file is opened in read-only mode. but this file can be shared via Facebook, gmail etc. I want to restrict it from sharing, as per privacy purpose.
Thanks in advance
You would need to create a whitelist to limit which intent is fired when you want to open the PDF in an external application. See this for an approach.
[EDIT] If someone stumbles upon this question later, once you fire an intent to open an external application, there is no way to control what that application does with your document.
I need a pointer to a (preferably free) PDF viewer app that I can invoke on a file or URL link via a startActivity on an Intent. I know that there is no real standard - I have one phone that came with OpenOffice that can read local PDF files, and one phone that has no built-in PDF reader.
What I want is the name of an application that I can suggest to my users to download from the market that is a PDF viewer that I can invoke by configuring an Intent and calling startActivity. I would make this suggestion when I intercept a URL to a pdf file, and discover that the application is not yet installed. Although ugly, this is better than the blank screen they get now because the built in browser doesn't do PDF.
I already installed Adobe's PDF viewer but it is not showing up in the package manager as being a candidate to handle PDF files.
I have used the technique suggested in SO:how-to-render-pdf-in-android to examine the candidate activities for a URL based PDF link and a local file PDF link and see that the com.android.browser.Browser is always invoked for http:// URL links; a URL of "file.pdf" causes OpenOffice to be selected on one phone and nothing on the other phone. Adobe's PDF viewer is not a candidate for either approach.
I tried the Google Docs viewer approach (as suggested in SO:android-load-pdf-pdf-viewer but that leaves a lot to be desired, especially as the PDF image I tried to load kept moving further and further down the device's screen until a user would need to scroll several screen fulls of blank screen to get to the document.
I see libraries such as android-pdf-viewer as a potential solution. But I'd prefer to link to another application rather than build in PDF support (including the fonts, etc) into my application. This then allows my application to support multiple PDF viewer applications - choosing one that the user has already installed or suggesting my favorite one if no compatible reader is present when I need it. Potentially I could see using these types of libraries to create such an application and load it to the market place, but before doing that I want to make sure that I'm not re-inventing the wheel.
I found the droid-reader application which looks promising, but this doesn't appear to be available from the market place. While I'm personally comfortable with the gymnastics of downloading files to my sdcard and installing from there, its not a viable option for the general public user that I'm targeting.
I hope the following code snippit would be helpful to you for reading pdfs. It will use the default pdf viewer that has been set on your device.
Intent intent= new Intent(Intent.ACTION_VIEW);
File f = new File("/mnt/sdcard/file.pdf");
intent.setDataAndType(Uri.fromFile(f),"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
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 am new to android programming, so i have a question regarding how to open any document such as .doc, .docx, .ppt, etc. in android. I also need to implement preview functionality, wherein the file should be downloaded temporarily and user can see the file opened just by a single click.
How does dropbox does this? Is there any intents available?
Can anybody help me out of this issue by some example or code?
Thanks.
Unlike iOS, Android itself does not support rendering .doc or .ppt files.
You are looking for a public intent that allows your app to reuse other apps' activities to display these document types. But this will only work for a phone that has an app installed that supports this Intent.
http://developer.android.com/guide/topics/intents/intents-filters.html
This may help: Android Launching an application chooser with appropriate list of applications