[英]java.lang.IllegalArgumentException: sortOrder not supported
下面的代码在第三和第四行的标题中引发异常。 我想念什么吗? 我希望能够按艺术家姓名排序。
public List<String> getAllArtists(Context context) {
List<String> artists = new ArrayList<String>();
String[] projection2 = {MediaStore.Audio.Media.ARTIST};
String sortOrder = MediaStore.Audio.Artists.ARTIST;
Uri songUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
CursorLoader cl2 = new CursorLoader(context,
songUri, projection2, null, null, sortOrder);
cursor = cl2.loadInBackground();
while (cursor.moveToNext()) {
if (cursor.getString(0).length()>0){
if (!artists.contains(cursor.getString(0)))
artists.add(cursor.getString(0));
}}
cursor.close();
return artists;}
这是完整的堆栈跟踪:
03年3月22日16:49:18.237 2594-2637 / php_request E / AndroidRuntime:致命例外:IntentService [SongService]进程:php_request,PID:2594 java.lang.IllegalArgumentException:android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils)不支持sortOrder .java:165),位于android.database.DataResourceResolver.query(ContentResolver.java:500),位于android.content.ContentProviderProxy.query(ContentProviderNative.java:421),位于android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)在android.content.CursorLoader.loadInBackground(CursorLoader.java:64)在SongParser.getAllArtists(SongParser.java:41)在SongService.onHandleIntent(SongService.java:60)在android.app.IntentService $ ServiceHandler.handleMessage(IntentService。的android.os.HandlerThread.run(HandlerThread.java:61)的android.os.Looper.loop(Looper.java:148)的android.os.Handler.dispatchMessage(Handler.java:102)的java:66)
您使用的是由Google Play音乐应用而非Android媒体系统专门处理的Uri。 ( com.google.android.music
是Play音乐的程序包名称。)我可以想象
a)Play音乐API不能与Android MediaStore
API混合使用,
b)如错误所示,Play音乐内容提供商不支持SQL排序,
c)Play Music API会随着时间而改变,因此无论如何都不要使用它。 (不要在此引用我的意思。)
也许您想使用http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html此处指定的Uri
常量之一。 这些是:
MediaStore.Audio.Media.INTERNAL_CONTENT_URI
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
如果打算使用指定的Uri
,则建议从内容提供者请求中删除sortOrder
,然后通过调用以下内容对结果List
排序
Collections.sort(artists);
似乎排序顺序API已更改。 您可以按ARTIST_KEY排序吗? 我只是在看http://developer.android.com/reference/android/provider/MediaStore.Audio.AudioColumns.html上的列,并且说它是可排序的。 当您使用空排序顺序时,您的查询也有效吗?
对于您的情况,您可以将其用于排序,
String sortOrder = MediaStore.Audio.Albums.DEFAULT_SORT_ORDER;
对于URI,您可以使用-
Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", artistId);
artistId是上一个Artist查询中MediaStore.Audio.Artists._ID
的值。
在此, DEFAULT_SORT_ORDER:此表的默认排序顺序常数:“ artist_key”
希望对您有帮助。
将CursorLoader创建为CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
时,它会为您进行排序CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
因此,要查询艺术家列表,可以使用MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI
并将艺术家名称用作选择参数。 对于专辑列表,您现在具有ARTIST_KEY
,可用于查询MediaStore.Audio.Artists.Albums.EXTERNAL_CONTENT_URI
,以获取给定艺术家的专辑列表。
资源链接: 媒体商店默认排序顺序
对于视频 ,您可以使用它
String orderBy = android.provider.MediaStore.Video.Media.DATE_TAKEN;
videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, orderBy + " DESC");
资源链接: 来自Mediastore的android列表中的排序顺序
用于为内容提供者指定查询的排序顺序,它看起来像
new CursorLoader(context, RepresentativeEntityContentProvider.CONTENT_URI, null, null,
null, "COLUMN_NAME ASC");
使用此功能,我们可以使其与COLUMN_NAME升序排列。
如果您使用的是带有Cursor或也许Content提供商的SQLite数据库,则可能会遇到有关大写和小写字母的字母排序问题。
String[] projection = { Table.COLUMN_ID, Table.COLUMN_TITLE};
String sortOrder = Table.COLUMN_TITLE + " COLLATE NOCASE ASC";
CursorLoader cursorLoader = new CursorLoader(this,
YourProvider.CONTENT_URI,
projection,
null,
null,
sortOrder);
字母排序问题的解决方案是在您指定排序的查询部分中的COLLATE NOCASE
。
注意,ASC是可选的,可以指定。 您也可以使用DESC
反转排序顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.