Search code examples
androidandroid-mediaplayerandroid-cursormediastore

How to filter ringtone, alarm and relevant media files in android


I am trying to retrieve music file from the android INTERNAL STORAGE URI but I am gettting the alarm and ringtones also I came to know about filtering from here .So i tried to set the duration equal to 30sec then also I am getting some alarm file .I can not set multiple condition this is what I tried

  String[] proj2 = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE};// Can include more data for more details and check it.
     String selection = MediaStore.Audio.Media.DURATION + ">=30000";
    Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, proj2, selection,null, null);

I tried to select by ringtone and is_music but then also i am getting some alarm files .So what should i try to filter all the ringtones ,alarm and other such inbuilt files


Solution

  • Hei man , I look up your code . Once I have faced the same problem while doing media Query with Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, proj2, selection,null, null);

    but Everything you did is perfect You just need to Query through Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    so your whole content resolver and query should be like this

    String[] proj2 = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE};// Can include more data for more details and check it.
     String selection = MediaStore.Audio.Media.DURATION + ">=30000";
    Cursor audioCursor = getContentResolver().query(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj2, selection,null, null);