Invalid Token is_music error in Android(Java)

Viewed 200

I have a music app. Nowadays, I want to upgrade my music app to Android 11. I am using 'Cursor' for the searching music files. But, I am getting an error. I searched error message and did this solutions however any solution didn't fix my issue. I will share code snippet and issue details. Can anybody help me about this bug?

Code Snippet

ContentResolver musicResolver = application.getContentResolver();
String SONG_WHERE_CLAUSE;
Cursor musicCursor;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
    String[] selectionArgs;
    if (scanAll) {
        SONG_WHERE_CLAUSE = "duration > ?";
        selectionArgs = new String[1];
        selectionArgs[0] = "5000";
    } else {
        SONG_WHERE_CLAUSE = MediaStore.Audio.AudioColumns.DURATION + " > ? AND " + MediaStore.Audio.AudioColumns.IS_MUSIC + " = ?";
        selectionArgs = new String[2];
        selectionArgs[0] = "3000";
        selectionArgs[1] = "1";
    }
    Bundle bundle = new Bundle();
    bundle.putInt(ContentResolver.QUERY_ARG_LIMIT, 50);
    bundle.putInt(ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING);
    bundle.putString(ContentResolver.QUERY_ARG_SORT_COLUMNS, MediaStore.MediaColumns.DATE_ADDED);
    bundle.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, SONG_WHERE_CLAUSE);
    bundle.putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs);
    musicCursor = application.getContentResolver().query(MediaStore.Files.getContentUri("external"), null, bundle, null);
} else {
    SONG_WHERE_CLAUSE = "duration > 3000 AND " + MediaStore.Audio.Media.IS_MUSIC + " = 1";
    if (scanAll)
        SONG_WHERE_CLAUSE = "duration > 5000";
    musicCursor = musicResolver.query(musicUri, null, SONG_WHERE_CLAUSE, null, MEDIA_SORT);
}

Bug Detail

 java.lang.IllegalArgumentException: Invalid token is_music
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:472)
    at android.content.ContentResolver.query(ContentResolver.java:1183)

I am facing an error in this line ; musicCursor = application.getContentResolver().query(MediaStore.Files.getContentUri("external"), null, bundle, null);

Thanks.

0 Answers
Related