簡體   English   中英

如何排除 /storage/emulated/0/Ringtones 中的文件

[英]how to exclude files in /storage/emulated/0/Ringtones

當我使用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中?

你可以試試這個:

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM