【发布时间】:2022-10-07 15:33:29
【问题描述】:
我使用 file-picker 指南在 maui blazor 应用程序中显示文件选择器(底部参考代码)。
在 Windows 上这有效。
在 android 上,文件选择器打开并显示,但我无法点击任何文件,因为它们都被禁用(灰色文本)并且不可点击。
我已经将[assembly: UsesPermission(Android.Manifest.Permission.ReadExternalStorage)] 添加到MainApplication.cs 和<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 到AndroidManifest.xml。
将 apk 安装到我的设备或模拟器后,我授予了存储权限(因为我还没有实现对话框)。
如何使用 maui 应用程序在 android 设备上打开文件?
- Visual Studio 2022(最新更新)
- .NET 核心 6
<button @ref="button1" class="btn btn-primary" @onclick="OpenFileAsync">Open File</button>
@code {
public async void OpenFileAsync()
{
var customFileType = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "public.my.comic.extension" } }, // or general UTType values
{ DevicePlatform.Android, new[] { "application/comics" } },
{ DevicePlatform.WinUI, new[] { ".cbr", ".cbz" } },
{ DevicePlatform.Tizen, new[] { "*/*" } },
{ DevicePlatform.macOS, new[] { "cbr", "cbz" } }, // or general UTType values
});
PickOptions options = new()
{
PickerTitle = "Please select a comic file",
FileTypes = customFileType,
};
var result = await FilePicker.Default.PickAsync(options);
// ... process result
}
}
【问题讨论】:
标签: c# android maui maui-blazor