Issue where android downloads folder different in the files app then what is read pragmatically

huangapple go评论60阅读模式
英文:

Issue where android downloads folder different in the files app then what is read pragmatically

问题

code

 val downloadsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
        val toslist = downloadsFolder.listFiles()

        toslist?.forEach { file ->
            val cellValue = file.name
            print("$cellValue \n")
        }

我有一部运行 Android 12 的 Pixel 5,并从 Gmail 附件下载了 Excel 文件。在我的手机文件应用程序中,Excel 文件位于下载文件夹中。不确定为什么我无法以编程方式从那里读取它。从编程角度来看,我只能看到我从短信应用程序中下载的图像。

有人知道发生了什么或者这个文件可能在哪里吗?

英文:

When I go to print out the names of all the files in my downloads folder I see 4 of the 25+ files on my device print in console.

code

 val downloadsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
        val toslist = downloadsFolder.listFiles()

        toslist?.forEach { file ->
            val cellValue = file.name
            print("$cellValue \n")
        }

I have a pixel 5 running android 12 and downloaded the excel file off a gmail attachment. In the files app on my phone the excel file is in the downloads folder. Not sure why I can not read it there pragmatically. Pragmatically I can only see images I downloaded off my text messenger app.

Anyone have any idea what is happening or where this file might be?

答案1

得分: 1

在Android 11+设备上,您只会看到您的应用程序自己创建的文件。

英文:

On Android 11+ devices you will only see the files created by your app itself.

答案2

得分: 0

请在你以编程方式读取数据的代码部分包含它。可能情况是你只是打开文档来搜索图像。如果是的话,你还需要将 .xlsx 扩展名添加到以下代码中:

private val loadMediaWithDocuments =
        registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
    // 处理结果
}

然后使用这个代码

loadMediaWithDocuments.launch(
            arrayOf(
                "image/*",
                "video/*",
                "application/pdf",
                "text/plain" // 添加你想要查看的文件类型的期望扩展名,用于 OpenDocument 活动结果合同
            )
英文:

Please include the code where you are reading the data programmatically.
It might be the case that you have the open document to only search for images.
If yes you also have to add the .xlsx extension to the

private val loadMediaWithDocuments =
        registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
    //handle the result
    }

Then use this 
loadMediaWithDocuments.launch(
            arrayOf(
                "image/*",
                "video/*",
                "application/pdf",
                "text/plain" // add the desired extension of the file type you want to 
                              //see with OpenDocument activity result contrat
            )
            

huangapple
  • 本文由 发表于 2023年2月27日 10:35:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定