Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

android - AppData之外的Xamarin.Forms(UWP和Android)目录选择(Xamarin.Forms (UWP and Android) directory selection outside of AppData)

I've been pulling my hair out all day.

(我整天都在拔头发。)

I'm converting my WPF app to Xamarin.Forms (UWP, IOS and Android).

(我正在将WPF应用程序转换为Xamarin.Forms(UWP,IOS和Android)。)

I'm currently focused on UWP and Android (don't have an apple devices yet) and I got a lot of the program running but I ran into a huge snag with reading files that are not in my sandbox directory.

(我目前专注于UWP和Android(尚没有苹果设备),并且运行了很多程序,但是遇到了读取沙箱目录中未包含的文件的巨大麻烦。)

Currently, my app allows you to choose a folder with images and you can move through them.

(目前,我的应用程序允许您选择一个包含图像的文件夹,并且可以在它们之间移动。)

To test out the reading functionality, I've placed the images into the "LocalState" directory and bingo, my code is working beautifully.

(为了测试阅读功能,我将图像放入了“ LocalState”目录和宾果游戏中,我的代码运行得很漂亮。)

Now the program doesn't have a default folder and when I originally created it in WPF, the user would have a pop up and they would choose their own folder but I cannot for the life of me get a similar function for Xamarin.

(现在该程序没有默认文件夹,当我最初在WPF中创建它时,用户将弹出一个窗口,他们将选择自己的文件夹,但是我终生无法获得Xamarin的类似功能。)

Every time I try something, I get an "access denied".

(每次尝试尝试操作时,都会收到“访问被拒绝”的信息。)

I've seen Android apps allow you to pick a folder for emulators and I'm 100% sure that you can setup UWP to do permissions with StorageApplicationPermissions but I just cannot get this to work for Xamarin.Forms.

(我已经看到Android应用允许您为仿真器选择一个文件夹,而且我100%确定可以设置UWP来使用StorageApplicationPermissions进行权限,但我只是无法使它适用于Xamarin.Forms。)

Please help me!

(请帮我!)

  ask by dbooher2011 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK, Android first it is easier.

(好的,首先使用Android更容易。)

You need to setup in the manifest permissions to read and write SD-card.

(您需要在清单权限中设置读写SD卡的权限。)

On Marshmallow and later you need to ask for the permission at the runtime (you need to do that from the native project).

(在棉花糖及更高版本上,您需要在运行时请求许可(您需要从本机项目中进行许可)。)

On UWP the easiest thing to do would be to set the broadfileaccess in the manifest.

(在UWP上,最简单的方法是在清单中设置broadfileaccess。)

Other than that you pointed out to the proper APIs, just you need to run them natively.

(除了您指出了正确的API之外,您只需要本地运行它们即可。)

In general native code is called by using dependency injection.

(通常,使用依赖注入来调用本机代码。)

If it gets too complicated you may consider to create Xamarin.Forms project as a shared project where you can use conditional compiling instead of dependency injection which is quite simpler.

(如果太复杂了,您可以考虑将Xamarin.Forms项目创建为共享项目,在这里您可以使用条件编译而不是依赖注入,这非常简单。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...