How to invoke the default file chooser picker in Android? - android

If you go to imgur.com from your Android device, click on Upload an Image and then on Touch here to select your images, the Android prompts you with a Choose file for upload with few options. The good thing about this picker is that even if there is no camera as an option (for older phones) you can start the camera from the Gallery application, take a picture and eventually select it from the gallery to be uploaded.
That works also for any file <input> on any website.
So my question is: how can I invoke that file picker and eventually get the path to the selected image in native Java app?
If possible I would like to filter it so it will prompt only for images and not audio files and I don't want to install any file managers since it's doable within the browser. It's hard to believe that is available only for the Browser.
I don't want to implement my own file browser or list the camera's folder within my app. I'm also just starting with Android so a complete example to get eventually the file path or an image would be awesome.

Based on the chooser that comes up, <input> would appear to be requesting an ACTION_GET_CONTENT activity, with a MIME type of */*.
If possible I would like to filter it so it will prompt only for images and not audio files
Use a MIME type of image/*.
I'm also just starting with Android so a complete example to get eventually the file path or an image would be awesome.
See: https://stackoverflow.com/a/10274699/115145

Related

View postscript files on android

Is there a free way to view postscript files on android? I cannot find a solution online but surely lots of people must want to do this.
Recently Sam Buss and I realized that you can upload the PS file to Google Drive and once its uploaded to your drive, the drive viewer will open and render the PS file on your android device.
Here is a way that just worked for me on a Samsung Galaxy 5. Something similar can probably work for others. The general idea is to download the postscript file, and use an online web service to convert it to PDF, which you can then view.
Download the postscript file.
Open your browser (I use Chrome). Navigate to www.ps2pdf.com. Navigate your way to their "Convert" page, click the "Choose file" botton. Select "Documents" when it asks for "Choose an action". Go into your "Downloads" folder on your phone. Select the downloaded postscript file. Then, back on the ps2.pdf.com page, click the Convert button.
Click the active link for the converted PDF file. This opened in Adobe Reader, which is my default PDF viewer). If I want to access the file from other programs, it is in Adobe Reader's "Recent" folder in my phone's documents.

Android file picker and standard mime types

I want to start another activity so the user can pick a file to use in my app. (Specifically an audio file in this case.) I googled and found this:
http://android-er.blogspot.com/2011/03/pick-file-using-intentactiongetcontent.html.
Basically it creates an Intent with ACTION_GET_CONTENT and mime type "file/*". Questions:
Where is it documented, in the standard Android docs, that this will start a file chooser?
Can I depend on it? That is, is it part of Android or does it only work if the user has a certain file manager app installed.
Is this the best way to choose a file? I specifically want an audio file (mp3, etc) - one of the audio files on the SD card that the standard music player knows about, somehow. Should I look at ContentProviders?
http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT

Android PDF viewer app to be invoked

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

How to show preview of file and open up file in its application in Android?

I have a option to attach files within a application. I this I need to show users a preview or a icon for specific item type. Icons with extension .txt, .doc, .pdf, .jpeg, .mp4 need to have its own specific icons or if possible a good preview thumbnail icon. And when the user wants to view it he would be clicking on the icon or preview. I need to start a intent to view the file.
I mean a pdf should open up in a pdf reader, or a txt or doc should open in text reader, a mp3 or mp4 should open up in a audio or video player.. and the important part I want them to com back to my application when they do a back out of the view application.
The only idea in my mind is to search through the file name and manually split out the extension and do a string compare to check it against the constant string values like ".mp3" or ".mp4" etc. This is not a good idea as there are lot of extensions for image, audio and video type. Please let me know if there is any straight forward way to do this. Thank you for your help.
You could also read the mime type of the file and do it that way. Might be more accurate than just reading the extension although both would probably work.
http://developer.android.com/reference/android/webkit/MimeTypeMap.html
guessContentTypeFromStream(InputStream)
You can then have an array list of drawables that refer to each icon.

System call to open a pdf on Entourage eDGe's E-Reader

I am trying to write an app that requires different PDF files to be opened and displayed on the E-Reader side of the eDGe's dual screens while the app is running on the LCD side. I've been using Better Terminal Emulator to cruise around the eDGe's file system but can't seem to find the command that opens PDF files. Does anyone know it or is there even one?
I'm going to answer my own question in case someone runs into the same issue. Using an intent with the action set as ACTION_VIEW, the mime type set as application/pdf, and a pdf file as the data, the Library will handle the intent.

Categories

Resources