Is it possible to create shared preference files in sdcard - android

Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.

You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.

it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .

Related

Can anyone tell me about InternalStorage in Android ? I am confused

I am new to android . I have little confusion on internal storage topic in android. Please correct me if i am worng
InternalStorage :- Allows us to read and write file that are associated with each application's internal memory so the data are private to your app.
This file can only be accessed by the application and cannot be accessed by other application or users
Is it true that InternalStorage store data in device internal memory ?
If answer is yes then how can i store images ,videos etc that user can see and access it on device or by pc when they are connected through usb?
if my app downloads an image and device does not have sdcard and i have used internalstorage method in this condition how user can see dowloaded image using usb or from device ?
It will be good if explanation is given with example .Thanks in advance
You must save your files on external storage. Notice that external storage does not automatically mean removable storage. Normally the devices built-in storage is divided into internal and external storage. However, external storage also includes removable storage like SD cards.
So, if you want to save files that the user should be able to access for example with his PC you should save to the external storage.
The respective user guides on that topic are in particular:
https://developer.android.com/training/basics/data-storage/files.html#InternalVsExternalStorage
https://developer.android.com/guide/topics/data/data-storage.html
For example, if you want to save a picture that is accessible by the user in the expected directory you would use
File picture = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "filename.png");
Since API level 17, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE are deprecated in internal storage method.so, you cannot write a file that can be accessed by user using internal storage method.
try External Storage to write file so that you can access.for more
https://developer.android.com/guide/topics/data/data-storage.html

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.

Reading From a file in android that is private to the Application

I am developing an android application and i need to read words from a file to create a Trie. Is there a way i can write the file to internal storage on install so that only my application can access it, or should i hard code the words. Any suggestions are appreciated
If the file isn't going to change, you should put it in your assets directory. If it is going to change, you can copy it from your assets to internal storage and it'll be private. External storage (often an SD card) is word-readable.
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/reference/android/content/res/AssetManager.html

Android permanent storage

I want to create a file and I don't want it to be deleted when the application data is cleared. Is there a way for this in android, something like permanent storage ?
Yes, you can save to external storage (typically the SD card). See the section in the docs entitled Saving files that should be shared:
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.
You can use SQLite for permanent storage. It will do the job perfectly. Avoid using GetExternalFilesDir() if you do not want the data to be deleted when the application removed.
This tutorial from Google will tell you about all options for storage
Data Storage in Android

Files internal to applications

I read this sentence, form a book
"Files: Files internal to applications, which you can store on a
removable storage medium"
and I am confused, well I expect that "Files internal to applications" saved from my app that will be accessible only from my app. and that is true when you save them internally in the phone memory.
But as the sentence says , you can save files to the sdcard also. And that is great but I think that everyone with 'external storage read' privilege set in the manifest will be able to read your file, so that doesn't make it internal to the app, it makes it publicly available to everyone.
My question is:
Is there any way to store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app, others application to be prevented from reading the content ?
I know that if you put files in data/data//files these files are only available to the app with that package name
It is possible . For that you need to encrypt the data with some private key and write to SDCARD, when ever you want to process that data you have to decrypt it . So another app can't access your data without decrypt it.
Android Encryption Example.
store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app
I don't think so, For sdcard it is not possible.
The one way is store encrypted file in sdcard and key for it is you can put (keep) in your application's shared preference in private mode and decrypt the file from your application when you want to read it. But I think it some ugly way.

Categories

Resources