如何在Unity中获取android的内部存储器根目录? [英] How to get android's internal memory root in Unity?

查看:1395
本文介绍了如何在Unity中获取android的内部存储器根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多类似的问题,似乎很多人试图弄清楚,我找不到任何可以帮助我的答案.我正在使用Unity制作一个适用于Android的简单应用.

I have seen many similar questions, seems like a lot of people trying to figure it out, I couldn't find any answer that would help me. I am making a simple app for Android using Unity.

我想在android内部存储根目录中有一个文件夹,在我的电脑上看起来像:huaweiP30 \ internal storage \ videos \

I want to have a folder in android internal storage root, on my pc it looks like: huaweiP30\internal storage\videos\

我不需要向该文件夹写入任何内容,我希望我的应用列出该文件夹中的所有mp4视频,并能够使用统一视频播放器播放它们,我希望用户能够轻松添加更多内容只需将视频放到该文件夹​​中即可.我在Windows上对其进行了测试,该应用程序已按预期完成运行,现在我需要做的就是为它提供内部存储的正确路径. 另外,我可以让应用程序列出整个存储中的所有.mp4文件,如果这样做更容易.

I don't need to write anything to that folder, I want my app to list all the mp4 videos from that folder and be able to play them using unity video player, I want the user to be able to easily add more videos to it by just dropping them into that folder. I tested it on windows and the app is completed working as expected, all I need to do now is to give it the correct path to the internal storage. Alternatively I could have the app list all .mp4 files on the whole storage if that's easier to do.

我尝试了所有可以在网上找到的答案,其中有些对其他人有用.到目前为止,对我没有任何帮助.

I I tried all the answers that I was able to find online, some of which worked for other people. Nothing has worked for me so far.

将其用于在Windows上进行测试,并完全按照我的要求进行工作.我只是不知道该用什么替换该路径,以使其从内部存储\视频\

used this for testing on windows and works exactly how I want it. I just don't know what should I replace the path with to make it read from internal storage\videos\

string videosPath = "C:\Users\Admin\Downloads\";

string [] filePaths = Directory.GetFiles(videosPath,"*.mp4");

请帮助我解决该问题或找到其他解决方案,感谢您的帮助. 预先感谢.

Please help me either solve it or find an alternative resolution, I appreciate any help. Thanks in advance.

推荐答案

这比我想象的要容易!我研究了这么长时间,当我要做的就是疯狂时-在手机设置中,我进入了权限,内存并允许我的应用访问内存. 然后就像

This was easier than I thought! I was researching for so long and already going crazy when all I had to do is - in my phone settings I went to permissions, memory and allowed my app to access the memory. Then it's as simple as

string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android", StringComparison.Ordinal));
        videosPath = path +"/videos/";

获取路径.添加了

SearchOption.AllDirectories

这是使您的应用请求权限的方法,因此您不必手动允许它. https://docs.unity3d.com/Manual/android-RequestingPermissions.html

here is how to make your app ask for permissions so you don't have to manually allow it. https://docs.unity3d.com/Manual/android-RequestingPermissions.html

示例代码是关于麦克风的,但是您只需将其更改为ExternalStorageRead/Write,不必担心外部",它也适用于内部存储器.

The sample code is about microphone but all you need to do is just change it to ExternalStorageRead/Write, don't worry about 'External', it works for internal memory too.

这篇关于如何在Unity中获取android的内部存储器根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆