Jan Hakl
Jan Hakl

Reputation: 75

Internal storage in android

I would like to use the internal storage for my files. I use function getExternalFilesDir() which uses the internal storage only when there is no SD card mounted, otherwise it stores the files to SD card.

Is there a way how to use only internal storage (that which is accessible for user) even when is SD card mounted?

Thanks

Upvotes: 1

Views: 560

Answers (2)

LvN
LvN

Reputation: 711

As per Android Training documentation you can use Internal storage only for

  1. It's always available.
  2. Files saved here are accessible by only your app .
  3. When the user uninstalls your app, the system removes all your app's files from internal storage.

You can use internal storage as follows

File file = new File(context.getFilesDir(), filename); //Creates a new file 

Or you can follow this

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

Upvotes: 1

Sohail Zahid
Sohail Zahid

Reputation: 8149

getExternalFilesDir() will provide external storage path not internal to get internal storage path you have to use this method getFilesDir() check below code.

File file = new File(ctx.getFilesDir()+"/MyFolder");
file.mkdirs()

Upvotes: 2

Related Questions