简体   繁体   English

res/raw 文件夹中文件的完整路径

[英]Full path to files in res/raw folder

I have an Android app (targeting Android R - API lvl 30) which has bulk of its logic in c++. App reads a file in res folder and we can access it like - R.raw.dev, where dev is the config file.我有一个 Android 应用程序(目标为 Android R - API lvl 30),它的大部分逻辑在 c++ 中。应用程序读取 res 文件夹中的文件,我们可以像访问它一样访问它 - 8814668 file.raw.raw.where

My intention is to get the full path to this file and open it in C++ layer using fopen method.我的目的是获取此文件的完整路径并使用 fopen 方法在 C++ 层中打开它。 But I'm not able to get the full path to the file.但我无法获得文件的完整路径。

I have seen some suggestions of the following kind,我看到了以下一些建议,

Uri resRawUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + getPackageName() + R.raw.dev);

But this is an Uri....not a file path.但这是一个 Uri....不是文件路径。

I've heard of an alternative to the res folder, called assets, which gives more freedom than the res folder.我听说过一个名为 assets 的 res 文件夹的替代品,它比 res 文件夹提供更多的自由。 The methods of AssetManager , the class used to query the assets folder, return InputStream and others, but not the file path. AssetManager的方法 class 用于查询assets文件夹,返回InputStream等,不返回文件路径。

Is there a way to get the absolute file path to files in res or assets folder?有没有办法获取 res 或 assets 文件夹中文件的绝对文件路径? If its not possible in these two folders, how about external storage?如果在这两个文件夹中都不可能,那么外部存储呢? Is there a way to get the absolute file path, so that I can pass this path to C++ and open it using fopen?有没有办法获取绝对文件路径,以便我可以将此路径传递给 C++ 并使用 fopen 打开它?

My intention is to get the full path to this file我的目的是获取此文件的完整路径

Resources are not files on the device.资源不是设备上的文件。 They are files on your development machine.它们是您开发机器上的文件。 They are entries in an APK file on the device.它们是设备上 APK 文件中的条目。

Is there a way to get the absolute file path to files in res or assets folder?有没有办法获取 res 或 assets 文件夹中文件的绝对文件路径?

No, sorry.不,对不起。

If its not possible in these two folders, how about external storage?如果在这两个文件夹中都不可能,那么外部存储呢?

I would use internal storage, such as getFilesDir() or getCacheDir() on Context .我会在Context上使用内部存储,例如getFilesDir()getCacheDir()

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

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