How to browse for file in Android? - 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.

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.

android hide folder to sd card and share the image inside the hidden folder

i want to hide a folder created on my external storage the get the path of the hidden folder to share data found inside the hidden folder. how can i achieve this. what i have done since now.
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "/mdata/");
imagesFolder.mkdirs();
the sharing
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/mdata/"+path));
You can hide the folder from most scans etc. by prefixing it with a .. This will make it a UNIX hidden folder.
However, users can still browse it with a file manager or on their computer, and apps can still access it if they want to.
If you want your data completely hidden from other apps, store it on a private server. Even the internal storage can be read with root, and the external storage can be read by any app with the permission to do so.
If you want to hide folder in Android or any Linux based system just add . as prefix to folder or file name.
However if you mount your SD card on Windows machine then these folders will be visible, with the . in front of the folder name, as a normal folder.

Android, how to choose save file location?

is there any solution how to choose the saving files location?
maybe with the original file browser, to choose the destination?
thank you!
All you need is Android Directory Picker
Better to save files with your app namespace:
String extStorage = Environment.getExternalStorageState();
path = extStorage+"/Android/data/com.mydomain.myapp/";
It will be deleted when app gets uninstalled.
Here is actually everything about data storing.
http://developer.android.com/guide/topics/data/data-storage.html
From the above link:
If you're using API Level 7 or lower, use
getExternalStorageDirectory(), to open a File representing the
root of the external storage. You should then write your data in the
following directory:
/Android/data/<package_name>/files/
It's probably easiest and expected to save this out to the dedicated area on the external SD card.
You can get this folder by calling
file://localhost/Applications/android-sdk-macosx/docs/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
You can also append a sub-folder to reference the source better ie. your app.
You can either choose DIRECTORY_PICTURES or DIRECTORY_MOVIES. If it's user created I'd probably stick to pictures.
To be helpful you can also call the media scanner to add it to the appropriate content provider system wide.
sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory()))
);
If you MUST get a file chooser going, which isn't the recomened approach to expose the user to the file system. Try the file chooser form Open Intents. http://www.openintents.org/en/node/164

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

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.

Categories

Resources