Folder added on Android is not visible via USB

后端 未结 8 950
青春惊慌失措
青春惊慌失措 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:44

    It's work fine for me.

    MediaScannerConnection.scanFile work if there is file in directory (not directory)

    private fun checkMTPFolder(f: File, context: Context) {
       if (f.isDirectory) {
          val newFilePath = f.absolutePath + "/tempFIle"
          val newFile = File(newFilePath)
          newFile.mkdir()
    
          MediaScannerConnection.scanFile(context, arrayOf(newFilePath), null, object : MediaScannerConnection.OnScanCompletedListener {
                    override fun onScanCompleted(p0: String?, p1: Uri?) {
                        val removedFile = File(p0)
                        removedFile.delete()
                        MediaScannerConnection.scanFile(context,arrayOf(removedFile.absolutePath), null, null)
                    }
    
                })
       }
    }
    

提交回复
热议问题