View & Open files downloaded on Android device - android

I'm having an Android Ftp Client, I download different types of files (.txt , .pdf , .mp3) from the server. And then I list all the files I downloaded.
So my questions are as follows:
If the file is on the SD card & I listed the files by their names. What I want to do is that by clicking on the name the file is opened.
Meaning if the file name is "test.pdf" & I clicked on it it should be opened in the same way the pdf file is opened in the pdf viewer, Same thing goes for mp3 files for example, by clicking on the file I want it to be played.
Thanks alot for the help in advance

Create an ACTION_VIEW Intent, using Uri.fromFile() for the Uri, and with a MIME type suitable for the type of content (e.g., you might decide to use application/pdf for .pdf files). Then, call startActivity() on that Intent.
There may be an open source Android file manager app that you could examine to see how they approach it.

Related

How to browse for file in Android?

In my App, I need to browse for local/external storage HTML files and display them on a WebView.
How do I activate such Intent action to popup the build-in file manager and return a result as the full path to the file selected?
Cheers.
There are no standard app doing that, you must write your own solution. You should use File.listFiles(); for listing files in given directory, together with Environment.getExternalStorageDirectory to get path to external storage.

android cannot open downloaded file

I successfully download a pdf file from the internet and then I open the downloads folder using the following Intent:
Intent pdfFileIntent = new Intent();
pdfFileIntent.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
ctx.startActivity(pdfFileIntent);
This code is located within the onReceive() method of a BroadcastReceiver I created to deal with download complete events.
The download is complete and successful (I can see the download status in the downloads folder, which is opened right after the download is complete, as expected). However, when I click the newly downloaded file, another dialog pops up which requests me to select the application with which the file will be opened (I can select either Adobe Reader or Quickoffice). When I select Adobe Reader, I get the error : "The document path is not valid" and when I select Quickoffice, I get the error: "File cannot be opened".
This is terribly annoying especially because the downloads folder and the download process and management of downloaded files is completely out of my hands - Android is aware of the files in the downloads directory when it presents them to me, so how can it be that it doesn't pass a valid path? What is going on?
To make things clear, I didn't specify any path in my code - Android chose the path in which to save the file. And I can even see that the file has a reasonable size in KBs, which means it's not empty and it's definitely a pdf file (.pdf extension).
Please help. Thanks in advance.
And I can even see that the file has a reasonable size in KBs, which means it's not empty and it's definitely a pdf file (.pdf extension).
The fact that a file has the PDF extension doesn't necessarily make it a valid PDF file! Move the file to your PC and see whether you can open it there. You may have a bug in the code performing the download, causing some invalid content to be written to the file.

How to open pdf file in package path in android?

In my application i need to open pdf file.For that i have prepared code to open pdf file.Suppose my pdf file in sdcard, It is working fine.when my application change from sdcard to application path i.e /data/data/app.package/ it is not working.I got alert dialog like
Invalid file path .Please guide me to over some this problem.
/data/data/app.package/ is package private. To share this pdf you'd probably have to move it to external storage (you can use getExternalFilesDir()). This directory has no security enforced.
You must make /data/data/app.package/file.pdf redable for other applications.
1) using openFileOutput(fname, Context.MODE_WORLD_READABLE).close(); create share file in your app data directory.
2) write pdf file to created file using Streams (you may write to stream returnet by openFileOutput instead of close it)
3) open your pdf file

after downloading a file in android where it will be stored?

in my application, user downloads any ebook format file from the web site and i need to handle that downloaded file in my code for the purpose of -Enable the user to view the ebook in a android device.
how to get control of a file after downloaded in to sdcard
how to change its file extension and file content
i found following answers:
we can use file handling Technic to move ,copy etc
to know its MIME type we can use setOnDownloadListner.

android get full path to my application via share option

I am writing an application where my application should show as option when user shares a file ( any type image or normal text file or pdf or with with no extension)
I know it for file like image by adding image/* as data in manifest file and i can able to handle image as URI.
But I needed it for any file type.
Another example is, I open file browser and select a file (can be any type) then in share option my application should appear to handle.
How can I modify my application for this case
You need to add mimeTypes for all file types you wish to handle.
More information at:
http://developer.android.com/training/sharing/receive.html

Categories

Resources