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

Java 如何排除/storage/simulated/0/Ringtones中的文件,java,android,android-cursoradapter,Java,Android,Android Cursoradapter,当我使用adb时,我找不到/storage/emulated/0文件夹。我基本上是尝试在内部存储器中加载所有音频文件,但尝试排除系统特定音频,如铃声和通知音,如按键音等。我有以下代码: String[] mediaAttrs = { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA, Me

当我使用
adb
时,我找不到
/storage/emulated/0
文件夹。我基本上是尝试在
内部存储器中加载所有音频文件
,但尝试排除系统特定音频,如铃声和通知音,如按键音等。我有以下代码:

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
下的所有音频文件都被排除在外,只有两个文件:

  • /storage/simulated/0/Ringtones/hangouts\u incoming\u call.ogg
  • /storage/simulated/0/Ringtones/hangouts\u message.ogg
  • 始终显示在
    列表视图中,当我使用
    adb
    查看该文件夹时,该文件夹不存在,该文件夹是什么?它是在运行时创建的吗?那么音频是如何到达那里的呢?我该如何避免它们被填充到
    列表视图中?

    您能试试这个吗:

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

    你能解释一下%的意思吗?这个查询实际上给出了一个错误。我不知道列名是否错了。(我发现了%similor-to-sqlite-not-like语句)要查找名称包含“铃声”或“系统”文字字符串的曲目,可以在模式的开头和结尾使用%wildcard。