How to open pdf file in package path in android? - 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

Related

Android excel file reading by user selection

Android file reading. I am learning android and a beginner. I wish create an app in which user can can download and excel file into the external storage(I mean accessible internal storage and preferably not SD card). On button click file browser should pop and user can guide to the file. Later reading the file in android. I have seen lot resource folder and asset folder. This is not I want. If anyone have done this please help. Struggling for a quiet long to achieve this. So far using the URI I am able to get the root folder and select the file but not sure how to select the file.

Giving another apps access to my app's file

I'm geting a file from server, and storing it on the phone. It's a PDF. Then I need to display . Assuming that I have a PDF viewer it will open the file.
The question is where should I store the PDF file so my pdf reader has access to it. I don't really want use external storage since not all phones has one. Is there a way to save public file on internal storage?
Or there is some way to pass the necessary information using ContentProvider. Unfortunately I would need some sample code of that.
All you put under internal directory can't be access by other applications. so getDir or getCacheDir have to be used only for your application.
If you need files to be open by other application you have to write files under SD card.

How to copy to and run an html5 file present in an Android phone's memory?

I am developing an android application, that should open html 5 file when it launches. What I did was
I saved the complete html application under android Assets folder.
I am not able to run the html file in the external browser using the path of assets folder directly, Following code which I used
Intent browserIntent = new Intent("android.intent.action.VIEW",
Uri.parse("file:///android_assets/mobile/index.html"));
startActivity(browserIntent);
An exception is thrown.
I send this folder to phone’s internal memory and From there I want to run it.
Qn 1. How can I send a file into phone memory?
Qn 2. And can I run that html file from phone memory?
Is it possible to do so??
First, use file:///android_asset/mobile/index.html instead. While the directory on the filesystem is assets/ (plural), the URL format uses asset (singular).
Second, you cannot open a Web browser on one of your assets. You will need to either:
Copy the files to external storage and launch the default browser on them
Copy the files to internal storage, create a ContentProvider to serve them, and launch the default browser on the resulting content:// path
This sample project demonstrates the second approach, albeit using a single PDF file than a directory of assets.
A third possibility is for you to display the contents yourself using a WebView widget.

View & Open files downloaded on Android device

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.

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.

Categories

Resources