简体   繁体   中英

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.

My intention is to get the full path to this file and open it in C++ layer using fopen method. 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.

I've heard of an alternative to the res folder, called assets, which gives more freedom than the res folder. The methods of AssetManager , the class used to query the assets folder, return InputStream and others, but not the file path.

Is there a way to get the absolute file path to files in res or assets folder? 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?

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.

Is there a way to get the absolute file path to files in res or assets folder?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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