如何解决AndroidJava中的无效令牌is_music错误
我有一个音乐应用。现在,我想将我的音乐应用程序升级到 Android 11。我正在使用“光标”来搜索音乐文件。但是,我收到一个错误。我搜索了错误消息并执行了此解决方案,但是任何解决方案都无法解决我的问题。我将分享代码片段和问题细节。有人可以帮我解决这个错误吗?
代码片段
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,SONG_WHERE_CLAUSE,MEDIA_SORT);
}
错误详情
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)
我在这一行遇到错误; musicCursor = application.getContentResolver().query(MediaStore.Files.getContentUri("external"),null);
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。