I was previously using getExternalStorageDirectory() which allowed my Android app to read and write files in the sdcard/music directory (/storage/emulated/0/Music). This way I was able to manually exchange these files with my Windows PC through the USB port with Windows Explorer.
Could someone show me or give me a hint on how I can transfer these files between my app and Windows Explorer now that getExternalStorageDirectory() is not working for API29.
This is the lines of code that I need to replace:
public class BrowseMusic extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse_decoder);
this.setTitle("Browse");
FilenameFilter filter = new GenericExtFilter(".evs",".EVS",".pcap",".PCAP");
String[] listOfFiles = Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_MUSIC).list(filter);
{
if (listOfFiles != null) {
ListView codecFileList = (ListView) findViewById(R.id.listD);
codecFileList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listOfFiles));
codecFileList.setOnItemClickListener(new returnClickedItem());
}
}
}
With the above code I used to be able to list the directory /storage/emulated/0/Music and I was able to later access the files that my app created through the usb cable.
But if I use getExternalFilesDir() instead
String[] listOfFiles = getExternalFilesDir(Environment.DIRECTORY_MUSIC).list(filter);
I can list the directory /storage/emulated/0/Android/data/com.mycompany.evsdemo/files/Music. This works fine for my app but I am not able to access that directory through the usb cable. In fact when I use Android Studio's Device File Explorer I can see the directory when working with an AVD but not with a physical Android Phone connected to usb. Any ideas are welcomed. Thanks.