我是靠谱客的博主 开朗糖豆,这篇文章主要介绍利用ContentResolver 读取本地视频数据出错,现在分享给大家,希望可以做个参考。

利用ContentResolver 读取本地视频大小和时长时,抛出了一个异常:Exceptionandroid.database.sqlite.SQLiteException: near “Girls”: syntax error(code 1): , while compiling: SELECT _id, title, _size, duration, _data FROM video WHERE (_data=’/mnt/hd/Movies/Wonder ‘Girls - Nobody.avi’)

String where = MediaStore.Audio.Media.DATA + "=" + "'"
+ mDataList.get(i).getPath() + "'";
//
where = _data='/mnt/hd/Movies/Wonder 'Girls - Nobody.avi'
cursor = resolver.query(uri, mCursorCols, where, null,
null);

当拿着where这个条件去通过ContentResolver 查询时,会抛出以上异常。
造成异常的原因可能是因为“Wonder” 后多出了一个“ ’ ”,导致在查找时程序会分不清该条件的具体范围,因此抛出了异常。

通过修改,将代码最终改为:

String where = MediaStore.Audio.Media.DATA + "= ?";
//
where = _data= ?
String[] selectionArgs = new String[]{mDataList.get(i)
.getPath()};
//
selectionArgs = /mnt/hd/Movies/Wonder 'Girls - Nobody.avi
cursor = resolver.query(uri, mCursorCols, where, selectionArgs,
null);

就可以正常读取,且不会抛出异常。
这样解决的原因如下:

这里写图片描述

最后

以上就是开朗糖豆最近收集整理的关于利用ContentResolver 读取本地视频数据出错的全部内容,更多相关利用ContentResolver内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(105)

评论列表共有 0 条评论

立即
投稿
返回
顶部