I have a Music player project in Android Studio, and I need to get all music from the device.
But somehow this.getContentResolver().query();
is not getting any music from my device.
In the logcat there is no log, and if I debug the app before the while loop and after it(because it does not enter in the while loop) it says that the cursor does not have any row(mCount = 0)
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
ContentResolver resolver = this.getContentResolver();
String[] projection = {
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST
};
String where = MediaStore.Audio.Media.IS_MUSIC + " != 0";
Cursor c = resolver.query(uri, projection, where, null, null);
if (c != null) {
while (c.moveToNext()) {
String path = c.getString(0);
String name = c.getString(1);
String album = c.getString(2);
String artist = c.getString(3);
Log.e("Name :" + name, " Album :" + album);
Log.e("Path :" + path, " Artist :" + artist);
}
c.close();
}