I have made an app that you puss a button and hear a ringtone!How can i add an option to save it to your device as a ringtone,if you like?thanks
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
It should be stored on a sdcard /Ringtones
If you want to save files that are not specific to your application and that should not be deleted when your application is uninstalled, save them to one of the public directories on the external storage. These directories lay at the root of the external storage, such as Music/, Pictures/, Ringtones/, and others.
and
In API Level 8 or greater, use getExternalStoragePublicDirectory(), passing it the type of public directory you want, such as DIRECTORY_MUSIC, DIRECTORY_PICTURES, DIRECTORY_RINGTONES, or others. This method will create the appropriate directory if necessary.
I read somewhere that you can put them in /media/ringtones but this isn't documented anywhere else. So you should use what they wrote in the docs.
Related
Where would the recommended location be to store an app licence file and a SQLite database for Android? Also, what are the constants used to point to those locations?
Note that the location(s) must be accessible without having to root the device, so the app data folder is not an option. I need to be able to access the files via a PC using a standard file manager.
I noticed that on the root folder of the device, there is a folder called "db" where other apps seem to store data. Is that a good location to store my db? If so, what is the Environment constant that points to it?
Depending on the level of security you want to achieve, there are numerous approaches to this issue.
At it's simplest you could store them at any folder on you external storage(Documents,Downloads e.t.c) or on your SD card provided that the user has given you permission AND has himself selected the path since newer Android Versions have reworked(restricted) the way an app can read/write from/to an SD card.
If for example you want to store it to "documents" folder you could do the following:
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),".dir");
This selects the "Documents" folder and creates a folder called dir. Note the "." before "dir" , meaning that the folder will be invisible as a first level of security. From here on you can create any number of directories or files you desire.
In my app I want to record a 2-second long sound and play it back to the user. All examples I've found so far require that the audio data for playback either comes from a file or from a URL.
Both MediaPlayer and SoundPool classes accept only files, file descriptors, resource id's or URLs as input and not just, say, a byte array.
Since one can only write files to the SD card and NOT internal storage (is this so?), the app would require that an SD card is mounted and writable. But my app should also work if no SD card is present.
Is there a way to achieve this?
Thanks
Yes, an App can write to internal storage (where it is installed). Every Installed app is provided a Data folder to write its internal files. Also there is a cache storage provided.
These methods of Context can get you these directories:
getCacheDir() : Returns the absolute path to the application specific cache directory on the filesystem (Note: System may delete cache if its low on storage)
getDir(String name, int mode) : Retrieve, creating if needed, a new directory in which the application can place its own custom data files.
Also there is a method for External storage: getExternalCacheDir() but is unreliable since external storage might not be always there.
Also, if you just need to write files in App's internal data directory, there is a very simple method:
openFileOutput (String name, int mode)
You can use
'getApplicationContext().getFilesDir().getAbsolutePath()'
to get the path of the directory where the app is installed.
One limitation is, 'getFilesDir()' gives you the path to the directory on the file system where files created with openFileOutput(String, int) are stored.
I need to store and read objects in Android, these Object must be available until they are manually deleted through the app.
Since I cannot use the assets folder for this,
How could I store objects in an hide folder to access them in future?
Well, you can keep them in your app specific directory in SD card. If you want the content inside your directory should not be scanned by mediascanner (so that they will not appear in Gallery etc), you need to keep a ".nomedia" file in that directory.
for example, create a directory called "mytestapp" in sdcard, and keep a ".nomedia" file there, along with the files you want to store
I am creating an app that could potentially be used in multiple educational establishments across a variety of courses with tutors who will want to be able to update some of the information within the app themselves on an ad hoc basis. I originally thought that the best way to do this would be to have the application download a new strings.xml file to the res/values folder, though I have read that you cannot update this folder/file whilst the app is packaged and running. I think a good work around for this would be to be able to save another strings.xml file elsewhere
My questions are:
Is this at all possible?
Where would I go about saving the strings.xml so that it is not
packaged when I export the app?
note: The file will not be called string.xml so there will be no confusion etc. with the actual strings.xml.
There is no "rule" of where you should put the file (minus, of couse system and other private folders you can't access). However, the logical and most common place to put a non-packaged resource that your app downloads would either be in your own applications data folder (located on the internal storage of the device) or on the external storage of the device (SD card).
To write your file to the internal storage you will need to use the context's openFileOutput(..) method. This stores the file within your apps private data directory. Use openFileInput(..) to read your stored file
To write to external storage you will need to add the WRITE_EXTERNAL_STORAGE permission to your manifest. After doing that, you can use FileOutputStream to write your files data when downloading. InputStream for reading (look up which input stream type would be most suitable)
Obviously, the examples I'm giving aren't fully detailed or have code but they will guide you in the right direction for storing files on your device.
Files under the res folder are used by the compiler to autogenerate the R class that contains the ids of the strings,layouts,drawables etc...
Of course you can download a custom resource from your server and stored it in the SD as #dymmeh points. And is the most reasonable way of to achieve modification of literals but be aware, you will not be able to use the #string/string_id in your layout's xml and you will have to parse the downloaded file yourself.
I would like to show a list of files in the Android phone.
For example, i would like my app to be able to list all images stored in the phone, i dont want a gallery view, just a simple list.
I would also like to be able to show all the audio files
any help would be appreciated
Thanks
I'm assuming you mean on external storage. Read up on Data Storage, which will tell you the correct way to go about navigating the file-system.
If you're using API Level 8 or
greater, use getExternalFilesDir() to
open a File that represents the
external storage directory where you
should save your files. This method
takes a type parameter that specifies
the type of subdirectory you want,
such as DIRECTORY_MUSIC and
DIRECTORY_RINGTONES (pass null to
receive the root of your application's
file directory). This method will
create the appropriate directory if
necessary. By specifying the type of
directory, you ensure that the
Android's media scanner will properly
categorize your files in the system
(for example, ringtones are identified
as ringtones and not music). If the
user uninstalls your application, this
directory and all its contents will be
deleted.
If you're using API Level 7 or lower,
use getExternalStorageDirectory(), to
open a File representing the root of
the external storage.
For standard/common media types such as Music, video and images in the internal memory, there are respective ContentProviders in the system that manage them. If you want to build list of such items you should consider querying respective ContentProviders (Google for MediaStore Provider).
However, if you want to build an exhaustive list of all the files in a particular directory, internal or external, you can use File#listFiles() API as was suggested by Fredley above.