Downloading Files - Location - android

This is a real newbie question.
I am going to be creating an app that downloads an XML file, which contains links to mp3 files.
Where should I download these files too?
I mean can I bundle the XML file under /res and then download the latest XML file over the top of it? Currently I have some mp3 files in /res/raw.
Would I be able to do the same?

I think you should save your XML file in your own directory in SD Card and just read that file content using XmlPullParser in your application.
File file = new File(Environment.getExternalStorageDirectory() + "/your_dir/your_xml.xml");
How to create Folder/Directory in SD card ?
How to read XML data from SD Card ?
I hope this is enough as per your requirement.

Related

Hide pdf and .mp4 files in Android

I'm developing an app that downloads .pdf and .mp4 files from a server. I'm saving this files on my SD card.
I need to hide these files to only be visible from my app.
Can someone help me?
Thanks!
Best regards.
Create a folder with a folder name starting with '.' (dot) and save files in this folder,it usually works on all linux versions and android
Best practice is to use internal storage. files saved to the internal storage are private to your application and other applications cannot access them. When the user uninstalls your application, these files are removed.
Create folder like this
File rootPath = getBaseContext().getDir("Yourfoldername", Context.MODE_PRIVATE);
if (!rootPath.isFile()) {
rootPath.mkdir();
}
File file = new File(rootPath, "sample.pdf");
Create a folder and Inside folder save your file with '.' before File name and save files, it will work on all versions of android

Keeping a text file in android

I am new to android and facing issue with file system usages.
I have seen several threads but i am still not able to find the answer which i am looking for my requirement.
I have a original file say test.xml which i want to keep somewhere in my eclipse project so that as soon as i install the app it should move my test.xml file into data directory so that i would be able to read it
please refere this link :
http://developer.android.com/training/basics/data-storage/files.html
I want to save my original file at : "/data/data/com.example.helloWorld/files"
I should be able to get the file handle form the below command
File file = new File(context.getFilesDir(), filename);
Please Note i dont want to save my file in asset folder.
Thanks,
Manish Bansal
I recommend you use assets as storage for your file initially as that will get compiled with your app, then once the user starts your app you check if your file exists and if not you can save the asset to the internal storage location as specified in the documentation, from there you can use the file as you like in the filesystem.

How to attach SD card files with apk

My project have multiple files in SD card. But when I install apk file on phone it does not work.
Please tell me how to attach those files with apk.
Your sdcard files cannot become the part of APK file, if you want those files to attach to your apk, insert them into asset folder or raw folder.
EDIT:
If you put your file in raw directory then:
com.your.package:raw/yourFile
Like this:
int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt");
File f = new File(context.getResources().openRawResource(resourceId));
And here's someone doing it with the assets folder:
Android Assets with sub folders
InputStream is = getAssets().open("subfolder/somefile.txt");
Create a sqlite database and store the path of whatever files you want to store on the sdcard. Also you can store them in assets folder depending upon the type of file but it is not a good practice as many say.
You could store the supporting files on a web server and have the application download the files to the sdcard on first run. This is what many games do. Google Play also offers free storage of files for applications.
Here is the Google blog post on large APK's
http://android-developers.blogspot.fr/2012/03/android-apps-break-50mb-barrier.html

image and file reference android

i'm making a hand-outs reader, i have an xml file contains the file link and the file thumbnail, i managed to parse the data inside the xml and save it in the sdcard.
having a /mnt/sdcard/App/File directory for the downloaded files(.pdf, .ppt files) and /mnt/sdcard/App/Thumbnail for the downloaded thumbnails(.png, .jpeg/.jpg files)
i want to reference the image to the downloaded file (like when i click the image the file will show or open the referenced file) is it possible? if yes how can i do that?
This tutorial should get you started on how to read/write from the SD card (if you don't already know how to do so), and this tutorial should show you how to retrieve and display images stored on the SD card.

Copy one file from assets to sd

I want to copy ONE file "test.txt" to the SD card.
I found tips on how to copy more than one, but they are not working for me...
The file is in the root of the assets folder "/test.txt"
Thanks.
I don't know if there is a native command for that, but you can always create a File, open the file you want to copy, and copy de byte array from one to another.

Categories

Resources