android - Get storage type of local path -


if have paths following:

  1. /storage/emulated/0/...
  2. /storage/usbdrivea/...
  3. /sdcard/...

i have following questions:

  • how find out storage located on? (usb stick, external storage, internal storage)
  • how find out type are? (primary storage (i have direct r/w access), secondary storage (on android >=4.4, don't have direct w access , need acquire right through storage access framework if need it))
  • how find out root path is?

results want

  1. this is: internal storage, primary storage, root path /storage/emulated/0/
  2. this is: usb stick, secondary storage, root path /storage/usbdrivea/
  3. this is: external storage, secondary storage, root path /sdcard/

i know paths may vary phone phone, how find out path located on storage , permissions have on paths? know can guess names of path, i'm interested in reliable way works on (or @ least on most) phones...

you need check access every primary , secondary storage through environment class. should this:

boolean canwrite =  environment.getexternalstoragedirectory().canwrite(); if(canwrite)// externalstorage 

and use environment.getrootdirectory() internal root

for usb need check

public static boolean isconnected(context context) {     intent = context.registerreceiver(null, new intentfilter("android.hardware.usb.action.usb_state"));     return intent.getextras().getboolean("connected"); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -