简体   繁体   English

Android设备内部存储的完整路径

[英]Android device internal storage full path

I am making AR video playback app. 我正在制作AR视频播放应用。 I want to play video from device storage instead of include it in the app. 我想播放设备存储中的视频,而不是将其包含在应用程序中。 In the path field in video texture I should write the path of the internal storage. 在视频纹理的路径字段中,我应该写内部存储的路径。 I wrote "/storage"emulated/0/Demo.mp4" (video's name is Demo) It works on the testing device, but when I try running the app on other device it does not work because the path differs (internal path is :/storage/sdcard0) What is the path should I wrote in the video texture to ensure running the app whatever the device is? 我写了“ / storage” emulated / 0 / Demo.mp4”(视频的名称为Demo),它可以在测试设备上运行,但是当我尝试在其他设备上运行该应用程序时,由于路径不同(内部路径为: / storage / sdcard0)应该在视频纹理中写入什么路径,以确保无论设备是什么,都可以运行该应用程序?

To find locations on internal storage for your app, use getFilesDir() , called on any Context (such as your Activity, to get a File object. 若要在应用程序的内部存储中查找位置,请使用在任何上下文(例如Activity getFilesDir()调用的getFilesDir()来获取File对象。

To get a location on external storage unique for your app, use getExternalFilesDir() , called on any Context (such as your Activity, to get a File object. 若要在您的应用程序唯一的外部存储上获得位置,请使用在任何上下文(例如Activity getExternalFilesDir()调用的getExternalFilesDir()来获取File对象。

To get a standard location on external storage for common types of files (eg, movies), use getExternalStoragePublicDirectory() on Environment. 要在外部存储器上为常见类型的文件(例如电影)获取标准位置,请在Environment上使用getExternalStoragePublicDirectory()

To get the root of external storage, use getExternalStorageDirectory() on Environment. 要获取外部存储的根,请在Environment上使用getExternalStorageDirectory() This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations. 但是,如今这被认为是草率的编程,因为它鼓励开发人员将文件放置在随机的位置。

Hardcoding things is not the best way but you could check if the video exists in 硬编码不是最好的方法,但是您可以检查视频是否存在

 /sdcard
 /mnt/sdcard
 /storage/sdcard0
 /storage/emulated/0
 /storage/emulated/legacyode

at least those are the most common places for android devices. 至少那些是android设备最常见的地方。 Then set the patch programatically instead of using the inspector 然后以编程方式设置补丁,而不是使用检查器

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

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