gpt4 book ai didi

How to Open Files on Xamarin Android Using FilePicker(如何使用FilePicker在Xamarin Android上打开文件)

转载 作者:bug小助手 更新时间:2023-10-27 21:05:36 25 4
gpt4 key购买 nike



I asked a similar question several days ago but couldn't reply or use until now (due to work issues). Anyway, here's the code I have:

几天前我问了一个类似的问题,但直到现在才能回复或使用(由于工作问题)。不管怎样,这是我的代码:


    using Xamarin.Essentials; (at the top of the file)
async Task<FileResult> PickAndShow(PickOptions options)
{

try
{
var result = await FilePicker.PickAsync(options);
if (result != null)
{
string Text = $"File Name: {result.FileName}";
if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
var stream = await result.OpenReadAsync();
Image = ImageSource.FromStream(() => stream);
}
}

return result;
}
catch (Exception ex)
{
// The user canceled or something went wrong
}

return null;
}

But I get this error:

但我得到了这样的错误:


   The name FilePicker does not exist in the current context. 

There are several other similar errors.

还有其他几个类似的错误。


Any help is very appreciated.

如有任何帮助,我们不胜感激。


RON

罗恩


更多回答

The FilePicker is the api of the Xamarin.Essentials, so this error shouldn't appear if you add using Xamarin.Essentials; in the right place.

FilePicker是Xamarin.Essentials的API,所以如果在正确的位置使用Xamarin.Essentials;添加,应该不会出现此错误。

I agree. Mystified. The using statement is at the beginning of the file, with the rest of them.

我同意。莫名其妙。Using语句位于文件的开头,其余语句位于文件的开头。

Did you try to clean and rebuild the project?

你有没有试着清理和重建这个项目?

Yes. Deleted the using statement for Essentials, etc. Deleted the bin and obj folders. Unloaded VS. Restarted VS, added the using statement for essentials. Cleaned; rebuilt all. Same result.

是。删除了Essentials等的Using语句。删除了bin和obj文件夹。卸载VS。重新启动了VS,添加了Essentials的Using语句。全部清理;重建。结果是一样的。

Yes. Clean and rebuilt. I've deployed the app for about a year+, no problems. Now. one problem after another. (see my next problem)

是。清理和重建。我已经部署了这款应用大约一年多了,没有问题。现在。一个接一个的问题。(参见我的下一个问题)

优秀答案推荐

Hi I had the same problem and I solved it using Xamarin.essentials 1.7 (until here) , but not work in 1.6 less or 1.7 >

嗨,我有同样的问题,我用Xamarin.Essentials 1.7解决了它(直到现在),但不能在1.6或1.7中工作>


更多回答

Thanks!!! It's been a long while since I downloaded via nuget.

谢谢!我已经很久没有通过Nuget下载了。

I did install 1.8. But I still have the same problem. (See my new problem post)

安装1.8但我还是有同样的问题。(See我的新问题(My New Problem)

Can you create a clear proyect? , and try it , the first that you install is xamarin.essentials, I use xamarin.essentials for geoloc the version 1.6,and this is working well

你能创建一个Clear Proyect吗?试一试,你安装的第一个是xamarin.essentials,我使用xamarin.essentials for geoloc版本1.6,这个运行得很好

It's now working ok, to an extent. I can click on a button to open and look at files in the Documents (or other) folders and I can open them.

在某种程度上,它现在运行得很好。我可以点击一个按钮打开并查看Documents(或其他)文件夹中的文件,然后我就可以打开它们。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com