Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MediaStore

 MediaStore

Keishin Yokomaku

May 27, 2016
Tweet

More Decks by Keishin Yokomaku

Other Decks in Technology

Transcript

  1. @KeithYokoma • Keishin Yokomaku at Drivemode, Inc. • Work •

    Android apps • Android Training and its publication • Like • Bicycle, Photography, Tumblr and Motorsport • ·͓ͨલ͔ 
  2. MediaStore is Կ • ୺຤ʹอଘ͞ΕͨԻָɾը૾ɾಈըͷ؅ཧΛ͢Δσʔλϕʔε • MediaStore.Audio, MediaStore.Images, MediaStore.Video •

    Uri ͱ֤छͷΧϥϜ৘ใ͕ఏڙ͞Ε͍ͯΔ • EXTERNAL_CONTENT_URI ͱ INTERNAL_CONTENT_URI • MediaStore.Audio.Media ΍ MediaStore.Images.Media ͳͲ 
  3. MediaStore is Կ public class SampleActivity extends Activity { @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor albums = null; try { albums = getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null); } finally { if (albums != null) albums.close(); } } } 
  4. MediaStore is Կ public class SampleActivity extends Activity { @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor albums = null; try { albums = getContentResolver().query( MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null); } finally { if (albums != null) albums.close(); } } } 
  5. Ṗଟ͖ MediaStore • Ҿ͖ํ͕͍·͍ͪෆ໌ͳσʔλ • ద੾ͳ Uri Λ࢖Θͳ͍ͱऔͬͯ͜Εͳ͍ΧϥϜ͕͋Δ • શΧϥϜΛऔಘͨ͠ͱ͖ʹԿ͕ೖͬͯΔ͔ϫΧϥφΠ

    • υΩϡϝϯτʹͳ͍ Uri ͕͋ͬͨΓɺͦΕΛ࢖Θͳ͍ͱ໘౗͍࣮͘͞૷ Λ͠ͳ͍ͱ͍͚ͳ͔ͬͨΓ͢Δ • ΄΅ϊʔίϝϯτɾυΩϡϝϯτ 
  6. Ṗଟ͖ MediaStore • ੲͷΪϟϥϦʔΞϓϦ͸ MediaStore ʹ SQL ΠϯδΣΫγϣϯΛ͍ͯͨ͠ • ࣸਅΛσΟϨΫτϦ͝ͱʹ෼͚Δ֓೦͸ը૾ͻͱͭͻͱͭͷσʔλʹ݁

    ߹͍ͯ͠Δ • άϧʔϓԽ͠ͳ͍ͱσΟϨΫτϦͷ֓೦͕ͱΓͩͤͳ͍ • ContentResolver ʹάϧʔϓԽͷ API ͸ͳ͍ • SQL ΠϯδΣΫγϣϯͰରԠ͢Δߥۀ 
  7. Ͳ͏͢Δ • ະ஌ͳ෦෼͕ଟ͍ͱ͸͍͑ɺ෼͔ͬͯ͠·͑͹Ҿ͖ํ͸ҰఆʹͳΔ • ϘΠϥʔϓϨʔτԽ͢Δͷ͸໨ʹݟ͍͑ͯΔ • Cursor Λͦͷ··࢖͏ͷ͸ؾ͕໓ೖΔ • ·ͩ

    ContentResolver Ͱফ໣͢Δͭ΋Γͳͷʁ • ੍໿৘ใ͸ϝιουͷҾ਺ͱͯ͠ඞͣࢦఆ͢ΔΑ͏ʹͯ͠ݟ͑ΔԽ͍ͨ͠ 
  8. ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade;

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } } 
  9. ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade;

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } } 
  10. ྫɿΞϧόϜ(Իָ)ͷऔಘ public class SampleActivity extends Activity { private AudioFacade facade;

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); facade = AudioFacade.getInstance(this); Cursor albums = null; try { albums = facade.album().fetchAlbum(); // do whatever you like with the album metadata } finally { if (albums != null) albums.close(); } } } 
  11. ྫɿΞϧόϜ(Իָ)ͷऔಘ AlbumCursor albums = null; try { albums = facade.album().fetchAlbum();

    while (albums.moveToNext()) { long id = albums.id(); String name = albums.displayName(); // …… } } finally { if (albums != null) albums.close(); } 
  12. ྫɿΞϧόϜ(Իָ)ͷऔಘ AlbumCursor albums = null; try { albums = facade.album().fetchAlbum();

    while (albums.moveToNext()) { long id = albums.id(); String name = albums.displayName(); // …… } } finally { if (albums != null) albums.close(); } 
  13. Α͞ • ContentResolver ܦ༝Ͱͷૢ࡞Λϥοϓ͠ɺԿΛҾ͖͍͔ͨ͝ͱʹϝιο υ͕Θ͔Ε͍ͯΔͷͰαοͱ࢖͑Δ • ୯७ͳߏ଄ͳͷͰ؆୯ʹ Rx ͳͲͰϥοϓͰ͖Δ •

    طଘͷ Android ͷ API ͱͷ਌࿨ੑ͸΄΅ͦͷ··(Loader ͸͋·Γߟ͑ͯ ͍ͳ͍) • औ͖ͬͯͨ Cursor ͔ΒϝιουҰൃͰͱΓ͍ͨσʔλʹΞΫηεͰ͖Δ • ൥Θ͍͠ΧϥϜ໊ࢦఆ͔ΒαϤφϥʂ