1

1)Question

I have used installLocation in manifest

 android:installLocation="preferExternal"

Correct me if i am wrong. android:installLocation="preferExternal" make your app install on external sdcard . If this is true then i should not be able to use myapplication when sdcard is removed . But however i can use myapplication even when i removed sdcard from my device

2)Question

what is the difference between sdcard0 and extsdcard on my device ? even when i use in my manifest

android:installLocation="preferExternal"

all app files are stored on sdcard0 and it is accessible even when i have sdcard in my device . i have used below method to store files on sdcard

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

So in which condition my files will be stored on my sdcard ? and how can i store files on extsdcard?

FaisalAhmed
  • 3,469
  • 7
  • 46
  • 76

1 Answers1

1

1) As stated in the docs:

If you declare "preferExternal", you request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage.

Unmounting the external storage means that all running apps that were installed there will be immediately killed. If you are still able to use your app, I see 2 possible reasons: the system decided to install your app on the internal storage OR your device also features an emulated "external" storage and your app was installed there.

2)

what is the difference between sdcard0 and extsdcard on my device

It's common that sdcard0 refers to the device internal storage while extsdcard refers to the external storage that might be physical or emulated. However there's no reliable naming convention, it's up to the vendor.

Also note that "external" an Android basically means "a storage that the user can access".
A few further steps that might help:

  • use ADB Shell to examine your device's storage structure, with SD card attached and detached

  • verify your app's install location from the "Apps" settings menu

  • Log absolute paths of directories provided by different methods of the Environment class

Note: generally, you should never rely on assumptions of your app's install location since that might get you in trouble on some devices

Droidman
  • 11,485
  • 17
  • 93
  • 141
  • In which condition files will be stored on extsdcard ? because it stores all files on sdcard0 whenever i use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); – FaisalAhmed Jul 06 '16 at 07:58
  • what do you use that directory for? Are you downloading some files to it? Also, please log the absolute path of your download directory (`Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()`) – Droidman Jul 06 '16 at 08:29
  • no i am not downloading anything . i am just storing image files to it for practice . my qestion is how can i store my file on extsdcard or in which condition it will store my image to extsdcard , because my image file goes in sdcard0 – FaisalAhmed Jul 06 '16 at 09:30
  • @FaisalAhmed `Environment.getExternalStorageDirectory()` should normally give you the external storage (if available) – Droidman Jul 06 '16 at 12:18