vendredi 6 novembre 2015

conten provider in android to save files in sqlite( data base)

how to save music files in content provider after that put on ListView in android for creating music player and what is the different of using content provider rather than directly access from SD

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String[] projection = new String[] {
                    MediaStore.Audio.AudioColumns.ALBUM,
                    MediaStore.Audio.AudioColumns.TITLE };
            Uri contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            Cursor cursor = getContentResolver().query(contentUri,
                    projection, null, null, null);
            // Get the index of the columns we need.
            int albumIdx = cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ALBUM);
            int titleIdx = cursor
                    .getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.TITLE);
            // Create an array to store the result set.
            String[] result = new String[cursor.getCount()];
            /*
             * Iterate over the Cursor, extracting each album name and song
             * title.
             */
            while (cursor.moveToNext()) {
                // Extract the song title.
                String title = cursor.getString(titleIdx);
                // Extract the album name.
                String album = cursor.getString(albumIdx);
                result[cursor.getPosition()] = title + " (" + album + ")";
            }
            // Close the Cursor.
            cursor.close();
        }

    });
}

Aucun commentaire:

Enregistrer un commentaire