简体   繁体   English

如何使用 do.net MAUI 从 Android 上的 USB 存储中读取文件?

[英]How to read a file from the USB storage on Android with dotnet MAUI?

How can I read a file from external USB storage on an Android device using the.Net MAUI Framework?如何使用 .Net MAUI Framework 从 Android 设备上的外部 USB 存储读取文件?

The reference here mentions Xamarin, but the idea is the same. 这里的参考提到了Xamarin,但是思路是一样的。

You can use the standard .NET APIs as mentioned in this quote from the documentation:您可以使用文档中引用的标准 .NET API:

Once a Xamarin.Android app has obtained the full path to a file, it should utilize any of the standard .NET APIs for creating, reading, writing, or deleting files.一旦 Xamarin.Android 应用程序获得文件的完整路径,它应该使用任何标准 .NET API 来创建、读取、写入或删除文件。 This maximizes the amount of cross platform compatible code for an app.这最大限度地增加了应用程序的跨平台兼容代码量。

This is another Xamarin link, but the idea is the same: 是另一个 Xamarin 链接,但思路是一样的:

Any of the C# APIs for writing to a file are sufficient;任何用于写入文件的 C# API 都足够; all that is necessary is to get the path to the file that is in the directory allocated to the application.所需要做的就是获取分配给应用程序的目录中的文件的路径。 It is strongly recommended that the async versions of the .NET APIs are used to minimize any issues that may be associate with file access blocking the main thread.强烈建议使用 .NET API 的异步版本,以尽量减少可能与阻塞主线程的文件访问相关的任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM