简体   繁体   English

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

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

When I use adb I can't find the /storage/emulated/0 folder.当我使用adb时,我找不到/storage/emulated/0文件夹。 I am basically trying to load all audio files in internal storage but trying to exclude system specific audio like ringtones and notification tones like touch tones etc. I have the following code:我基本上是在尝试将所有音频文件加载到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;

            }

Then I use the following to populate the list view:然后我使用以下内容填充列表视图:

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

The most weird thing is, all the audio files under /system get excluded but two files:最奇怪的是, /system下的所有音频文件都被排除在外,只有两个文件:

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

always appear in the ListView , the folder doesn't exist when I view it using adb , what is this folder?总是出现在ListView中,当我使用adb查看时该文件夹不存在,这个文件夹是什么? Is it created at runtime?它是在运行时创建的吗? Then how do the audio get there?那么音频是如何到达那里的呢? And How am I supposed to avoid them from being populated in the ListView ?我应该如何避免它们被填充到ListView中?

Can you try this:你可以试试这个:

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.

相关问题 访问存储在模拟存储中的文件 - Accessing files stored in emulated storage 文件夹Android内部存储中的文件的ArrayList / storage / emulated / 0 / - ArrayList for Files in Folder Android Internal Storage /storage/emulated/0/ 如何在内部存储中创建文件夹而不是 Android 中的 /storage/emulated/0? - How to create folder in the internal storage instead of /storage/emulated/0 in Android? 使用DownloadManager将文件下载到真正的SD卡,而不是模拟存储 - Use DownloadManager to download files to real SD card, not to emulated storage 模拟外部存储android - emulated external storage android 如何在android中创建外部存储目录,将外部存储路径显示为“storage / emulated / 0”? - How to create directory in external storage in android which show external storage path as “storage/emulated/0”? listFiles() 在 /storage/emulated 上返回 null,而 /storage/emulated/0 存在 - listFiles() returns null on /storage/emulated, while /storage/emulated/0 exists 如何将 TXT 文件写入“/storage/emulated/0/myapp/myfile.txt”,以便稍后从文件浏览器打开它们? - How can I write TXT files to "/storage/emulated/0/myapp/myfile.txt" so I can open them from file browser later? /storage/emulated/0/Notes/(没有那个文件或目录)? - /storage/emulated/0/Notes/ (No such file or directory)? Android Studio,/ storage / emulated / 0不存在 - Android studio, /storage/emulated/0 not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM