如何排除文件在存储emulated0铃声

问题描述 投票:0回答:1

当我使用 adb 我找不到 /storage/emulated/0 文件夹中。我基本上是想加载所有音频文件在 internal storage 但试图排除系统特定的音频,如铃声和通知音,如触摸音等。我有以下代码。

String[] mediaAttrs = {
                        MediaStore.Audio.Media.TITLE,
                        MediaStore.Audio.Media.DATA,
                        MediaStore.Audio.Media.ARTIST,
                        MediaStore.Audio.Media.ALBUM,
                        MediaStore.Audio.Media.DURATION,
                        MediaStore.Audio.Media.DATE_ADDED,
                };
mCursor = context.getContentResolver().query(
              MediaStore.Audio.Media.INTERNAL_CONTENT_URI,mediaAttrs,null,null,null);

String[] excludeLocations = {"/system","/storage/emulated/0/Ringtones"};

boolean locationInclude = true;
 while(mCursor.moveToNext()){
                String mediaLocation = mCursor.getString(mediaLocationIndex);//required column index
                for(String eachLocation:excludeLocations){
                    if(mediaLocation.startsWith(eachLocation)) {
                        Log.e("LocationTest:Excluded"," "+mediaLocation);
                        locationInclude = false;
                    }
                }

                if(locationInclude){
                    Log.e("LocationTest:Included"," "+mediaLocation);
                    this.insert( ... );//insert found data
                }
                locationInclude = true;

            }

然后我用下面的代码来填充列表视图。

Cursor mPlayListCursor = mDB.getWritableDB().query(
                Audio,//table name
                new String[]{"_id","mediaLocation"},
                null,null,null,null, "mediaLocation"+" ASC"
        );

SimpleCursorAdapter mAudioAdapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1,
                mCursor,
                new String[]{"mediaLocation"},
                new int[]{android.R.id.text1},0
                );  
ListView lv = findViewById(R.id.mListView);
lv.setAdapter(mAudioAdapter);  

最诡异的是,所有的音频文件都是在... /system 被排除,但有两个文件。

  1. /storage/emulated/0/Ringtones/hangouts_incoming_call.ogg
  2. /storage/emulated/0/Ringtones/hangouts_message.ogg

总是出现在 ListView当我使用以下方法查看时,该文件夹并不存在 adb,这个文件夹是什么?是在运行时创建的吗?那音频怎么会在那里?我如何避免它们被填充在 ListView?

java android android-cursoradapter
1个回答
2
投票

你可以试试这个。

String selection = MediaStore.Audio.Media.ALBUM + " not like ? and " + 
MediaStore.Audio.Media.DATA +  " not like ? ";
String [] args = {"%" + "ringtones" + "%", "%" + "system/" + "%"};

Cursor mCursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,mediaAttrs,selection,args,null);

while(mCursor.moveToNext()){
       // mCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)
   String mediaLocation = mCursor.getString(1);//required column index
   Log.d("LocationTest:Excluded"," "+mediaLocation);
}
© www.soinside.com 2019 - 2024. All rights reserved.