Folder added on Android is not visible via USB

后端 未结 8 959
青春惊慌失措
青春惊慌失措 2020-11-30 01:18

I\'m trying to save pictures in a subfolder on Android. Here\'s a bit of my code:

File path = Environment.getExternalStoragePublicDirectory(Environment.DIREC         


        
8条回答
  •  感动是毒
    2020-11-30 01:35

    I faced the same issue and rebooting either the Android device or the PC is not a practical solution for users. :)

    This issue is through the use of the MTP protocol (I hate this protocol). You have to initiate a rescan of the available files, and you can do this using the MediaScannerConnection class:

    // Snippet taken from question
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    path = new File(path, "SubDirName");
    path.mkdirs();
    
    // Initiate a media scan and put the new things into the path array to
    // make the scanner aware of the location and the files you want to see
    MediaScannerConnection.scanFile(this, new String[] {path.toString()}, null, null);
    

提交回复
热议问题