android - How to manage all local storages in all versions (primary, secondary storage, sd card, usb) -


intro

managing primary storage files + secondary storage files (local only): list informations have , extend them or correct me question becomes overview summarises main informations has know before starting work local storages. i'm sure many people looking such overview...

overview

normally have following storages:

  • a primary storage (always directly accessible, on internal storage, it's phone manufactorer)
  • a secondary storage (directly accessible android <=4.3)
  • other external storages usb otg example...

following questions raise up:

  1. how find out available local storages + find out type (primary, secondary resp. internal, sd card, usb)?

  2. list available files on storages

    2.1 storages indexed via mediastore?

    2.2 how files via mediastore?

    2.3 how files without mediastore?

  3. how edit files on storages?

most of things know, questions based on data indexed media store, how find out storages available, how identify storage... post answer answers of parts , shows status each questions <=> android version pair it's visible informations still missing

status - feel free extend/correct answers questions if know more or i'm wrong

android < 4.4

  • question 1 - partially known ✖
  • question 2.1 - unknown ✖
  • question 2.2 - known ✔
  • question 2.3 - known ✔
  • question 3 - known ✔

android 4.4

  • question 1 - partially known ✖
  • question 2.1 - unknown ✖
  • question 2.2 - known ✔
  • question 2.3 - partially known ✖
  • question 3 - partially known ✖

android >=5

  • question 1 - partially known ✖
  • question 2.1 - unknown ✖
  • question 2.2 - known ✔
  • question 2.3 - known ✔
  • question 3 - known ✔

----------------------------------------------

android <4.4:

----------------------------------------------

1. how find out available local storages + find out type (primary, secondary resp. internal, sd card, usb)? (partially known ✖)

i'm not sure how distinguish between available storage correctly... getting primary storage path possible via file primarystorage = context.getexternalcachedir(). or can paths via file[] dirs = contextcompat.getexternalfilesdirs(context, null);. list available paths, not sure if return usb storages or if reliable adds sd card paths...

i don't know how reliably find out path internal, whcih 1 sd card , 1 usb drive

2.1 storages indexed via mediastore? (unknown ✖)

i've seen external storages indexed , not, i'm not sure what's default behaviour...

2.2 how files via mediastore? (known ✔)

just list files via query on contentprovider following uri: mediastore.<audio,video,images,file>.media.external_content_uri, depending on data want

2.3 how files without mediastore? (known ✔)

on android version need android.permission.write_external_storage, can directly list files on external storages via file class. need know available root paths point 1

3. how edit files on storages? (known ✔)

can done directly via file class if have above mentioned permission in manifest.

----------------------------------------------

android 4.4:

----------------------------------------------

this device specific, not yet offer storage access framework limits access secondary storages!

1. how find out available local storages + find out type (primary, secondary resp. internal, sd card, usb)? (partially known ✖)

basically, should possible in same way on android < 4.4...

2.1 storages indexed via mediastore? (unknown ✖)

on device primary storage indexed, correct?

2.2 how files via mediastore? (known ✔)

works same way worked on android < 4.4...

2.3 how files without mediastore? (partially known ✖)

on primary storage works same way did on android <4.4. don't know how works on android version other local storages...

3. how edit files on storages? (partially known ✖)

primary storages files editable via file class. don't know how reliable write access other storages...

----------------------------------------------

android >=5:

----------------------------------------------

1. how find out available local storages + find out type (primary, secondary resp. internal, sd card, usb)? (partially known ✖)

getting primary storage possible before. don't know how list of other storages though. manual way let user choose root directory of secondary storage, sd card, usb stick following:

intent intent = new intent(intent.action_open_document_tree); intent.putextra(intent.extra_local_only, true); context.startactivityforresult(intent, 1234); 

and afterwards remember returned uri , persist uri when getting result storage access framework:

public void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == 1234)     {         if (resultcode == activity.result_ok)         {             // uri             uri treeuri = data.getdata();              // persist permissions             final int takeflags = data.getflags() & (intent.flag_grant_read_uri_permission | intent.flag_grant_write_uri_permission);             getcontentresolver().takepersistableuripermission(treeuri, takeflags);              // remember uri having access storage             // ...         }         return true;     }     return false; } 

i don't know how find out type (sd card, usb) of directory user selected though.

all files under root path readable , writeable via documentfile class.

2.1 storages indexed via mediastore? (unknown ✖)

only primary think. correct?

2.2 how files via mediastore? (known ✔)

works before...

2.3 how files without mediastore? (known ✔)

for primary storage, works before (just via file class), rest have use uri corresponding storage got in point 1. can use documentfile class files

3. how edit files on storages? (known ✔)

primary storages files editable via file class, rest editable via documentfile (with of tree uri point 1).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -