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.
Related
Well, I tried to search in google and SO, but didn't find much mainly because I am not sure what should be my search word. So, if anybody thinks this question is too generic and should be searched first, please help me providing some useful link.
What I want is, to have two buttons in my App which should download sample.csv and sample.php (I want to attach this file inside my App) file and save it to user directory, preferably in "download" folder or somewhere user can access easily.
I found this page by searching but here they demonstrates saving File on Internal Storage in App's folder only. Now I am confused whether this App's folder is accessible by browsing or not (I can't find my app's folder in my Samsung Note 2).
Another question pops up in my mind is, whether I have to read those sample files and create new file to save, or I can simply put a link and download the sample files I provided (more like HTML link)? Or may be I can just upload those sample files in my web server as zipped and give a link to dload?
Apology for my long email, but I am confused where to start.
Thanks,
You can not access your app's internal directory. However, what you can do is to use InputOutputStream to copy your file from the internal directory to your desired folder, and then delete the file from the app's directory. Try searching for copying files and you'll find multiple links.
i am making dictionary and i have so much data to load. I want that i create a project which first load the dictionary words in database and the after i use this .db file in my 2nd project which is dictionary project.
But i don't know how to get the .db file and copy it and paste it into my assets folder.
Well, yopu cant simply copy any files from one private storage, to another. I suppose you can archive this using different ways, for example:
1) Copy your .db file to SD card by first app, and copy it back to private storage by the second app.
2) You can use ContentProvider to share private data between 2 different applications without moving it on SD card.
You can'not get direct access to assest or any other data folder of different application. Good luck!
You can get resources from other package with PackageManager.getResourcesForApplication() method. Also you can share user id between your apps and sign them with share sertificate. In this case you can even share code base. +#Evos' suggestions.
I think share user id is your choise.
You can find examples and more info in this post and here.
Open Your previous project them open DDMS tab ,then go on path
data--->data---->your project---->databases--->.db file
now select that file and click on top right corner of screen here is a buuton to pull file from device to PC so click on that now a file dialog will appear select location to save file , now ok....this action will save your .db file on your selected location
now you can copy this file and put this file in your new projects assets folder and then use it.
I have an android application I am developing in Java.
I need it to load a text file so it can read what is in the text file and get values from it.
However, everything I have read so far has been directing me to use resources and package it up with the application.
However this means if I want to change the text file, I have to reinstall the application, which is not what I want.
I need to end up with the .apk file and the .txt file in the same folder on my android phone so I can change the .txt file and the app reads in the text file in its directory.
Can anyone help?
No, you do not want to end up with the .apk and the .txt file in the same folder.
You want to end up with the .txt in some place that's always the same and that you know about.
You can deploy the initial .txt via the ressources (aka: package it and copy it to the sd for example) and later download a new version (or copy something to the device via usb).
Then inside your app check if the file exists and open it with standard Java. There's plenty of source around for that.
I want to write an android application that can parse files. I have figured out the parser part of it but now I m stuck at how to actually input the files. The files can actually be anything - music files, image files, text files or video files. The parser recognises the file format and parses it accordingly. Can anyone tell me how to write the UI and code to actually input files (I am programming in java in eclipe). Ideally the user should be able to go through the folders in the phone, just like we do in the computer, and then choose which file.
Any help is greatly appreciated !
So what you need I think is a file browser or manager, right? Unfortunately, Android doesn't provide a native file manager,and you have two choices to select files in the sd card.
There are some free third-party file managers,such as ES file manager and OI file manager. They provide hook for the developers to call via Intent. I am using OI. It's open-source.
You can also implement your own file manager. Well, it would be a little more difficulty than the 1st solution and you have a lot of work to do. I may suggest you use a listView, and list the dirs in the sd card. You may use android.os.Environment class to check the state of the sd card and use java.io.File to get info about the dirs and files.Also, see here to learn how to read files from SD card.
I am creating android application which contains DB that needs to be hidden(not able to access by the user)in the SD Card. Can anyone tell me how to do this?
Any file stored on the SD card is accessible both by applications running on the phone, and by users who have mounted the SD card (both while it's in the phone and otherwise).
You can change the file properties to make it 'hidden', but it will still be easily found. There is no way to make a file on a public partition like an SD Card 'secure' in the manner you describe - users will always be able to copy, delete, and potentially change the file.
The best solution to your problem is to look into ways to encrypt your database to record it securely. You won't be able to prevent users from deleting or copying the file, but you should be able to make it difficult for them to read data from it or modify its contents.
For an easy solution, just prefix the db file with a . (like .dbfile). This will hide the file on Linux based systems, including android.
I am assuming that you want to hide the file to prevent users from accidentally deleting/changing it.
SD cards cannot be secured in the fashion you seek.
just name the file start by ."Dot"... ".myFolder/.myfile"
You can create a folder whose name starts with a dot(.) example (.dbfiles) android See these folders as configuration folder and do not show content of these folder in applications like gallery,music player...You can see these folders with advance file explorer like Es File explorer
Sdcard you cant't! Internal app data partition is the place for you.