过滤由文件扩展名(或,可替换地,文件类型)一个managedQuery为一个Android光标 [英] Filter a managedQuery by file extension (or, alternatively, file type) for an Android Cursor

查看:208
本文介绍了过滤由文件扩展名(或,可替换地,文件类型)一个managedQuery为一个Android光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Android SDK中,其中返回的结果是由各自的文件中的扩展的(例如,不是这个名字,必然)过滤做managedQuery。我已经做了相当多的研究和累,希望社会各界能帮助我。我敢肯定的答案就在那里,但是,代替读取SQL本书或什么的,我只是试图做一些事情这应该是pretty简单,但没有找到解决办法。

I want to do a managedQuery using Android SDK where the results returned are filtered by their respective file extension (e.g. not the name, necessarily). I've done quite a bit of researching and am tired and hoping the community can help me.. I'm sure the answer is out there but, in lieu of reading an SQL book or whatever, I'm just trying to do something that should be pretty simple but not finding the solution.

我想要做的是,从本质上讲,是这样的:

What I want to do is, essentially, something like:

managedQuery(Audio.Media.EXTERNAL_CONTENT_URI, myProjection, Audio.Media.DATA + " like ? ", new String[] {"%mp3%"}, null );

该作品不同之处在于,如果标题大概是mymp3.wav,这个查询仍然会返回它,因为MP3是的名字,但,那不是我想要的 - >我想这纯粹是过滤根据文件扩展名(或者,文件类型,如果是有办法做到这一点[例如,如果一个MP3的文件扩展名改为.WAV即使该文件的内容实际上是MP3,将工作为我的目的,好])。该解决方案应该说明的方式来筛选多个扩展名/文件类型(即,如果我想查询返回的所有.mp3文件以及.wav文件而不是.AMR文件,例如)。

This works EXCEPT that, if the title is something like "mymp3.wav", this query will still return it since 'mp3' is in the name but, that isn't what I want -> I want it filtered purely based on file extension (or, alternatively, file type if there is a way to do that [e.g. if an mp3's file extension name was changed to .wav even though the content of the file is actually mp3, that would work for my purposes as well]). The solution should indicate a way to filter for multiple extensions/file types (i.e. if I want the query to return all .mp3 files as well as .wav files but not .amr files, for example).

此外,虽然我中有你,我要的结果按字母顺序排序。我曾尝试是这样的:

Furthermore, while I have you, I want to sort the results alphabetically. I have tried something like:

managedQuery(Audio.Media.EXTERNAL_CONTENT_URI, myProjection, null, null, MediaStore.Audio.Media.TITLE + " ASC" );

不过,这并不过滤的全部的结果......这是说,返回的,比方说,MP3标题排序,然后,在最后名单,它就追加到列表中的.wav文件也按字母顺序排序,但我想整个列表是字母不分的文件类型。

However, that doesn't filter the entire results... that is to say that, the list returned is sorted by, say, mp3 title and then, at the end, it then appends to the list the .wav files also sorted alphabetically but I want the entire list to be alphabetical regardless of file type.

我知道有人在这里可以很容易地回答这个问题 - >先谢谢了!

I know someone on here can answer this easily -> thanks in advance!!!

推荐答案

我认为,所有你需要做的是改变%的mp3%% MP3 。这将迫使MP3是在文件名的末尾。

I think all you have to do is change %mp3% to %mp3. This will force "mp3" to be at the end of the filename.

如果您需要选择多种文件类型,像这样做:

If you need to select multiple file types, do it like this:

managedQuery(
  Audio.Media.EXTERNAL_CONTENT_URI,
  myProjection, 
  Audio.Media.DATA + " like ? OR " + Audio.Media.DATA + " like ? ", 
  new String[] {"%mp3","%wav"}, 
  MediaStore.Audio.Media.TITLE + " ASC" );

这篇关于过滤由文件扩展名(或,可替换地,文件类型)一个managedQuery为一个Android光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆