how can make Samples/XrSamples can access /sdcard/ files
I try to use XrSamples/XrBodyFaceEyeSocial as a reference
1) I modify its AndroidManifest.xml and add these user-permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
add android:requestLegacyExternalStorage="true" in its <application .. />
2) At the same time, I try to make this application get storage permission through
Settings->Privacy&safety->App permissions->Storage and turn on XrBodyFaceEyeSocial Sample
3) When I try add the following codes in
virtual bool AppInit(const xrJava* context) override {
...
...
int mFd = open("/sdcard/Movies/doggie.mp4", O_RDONLY);
if(mFd < 0) {
char* why = strerror(errno);
printf("%s\n", why);
}
else {
close(mFd);
}
}
I get mFd = -1 and the why = 0x000000775dedca94 "Permission denied"
4) I try to add these codes in its MainActivity
private static final String MANAGE_EXTERNAL_STORAGE = "android.permission.MANAGE_EXTERNAL_STORAGE";
...
if (checkSelfPermission(MANAGE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissionsToRequest.add(MANAGE_EXTERNAL_STORAGE);
}
and get the same result.
I wonder to know how to make this type of application can access /sdcard/ files. Appreciate for any comments.
Hi, To get the SampleXR apps working with files on the SD card, you’ll need to tweak a couple of things:
1. Permissions – Add READ_EXTERNAL_STORAGE (and WRITE_EXTERNAL_STORAGE if you need it) to your manifest. On Android 11+, you may also need scoped storage or the MANAGE_EXTERNAL_STORAGE permission.
2. Ask at runtime – Even if it’s in the manifest, you still have to request those permissions from the user when the app runs.
3. Use the right file access method – Direct file paths can be tricky with newer Android versions. Often you’ll need to go through the Storage Access Framework (SAF) or work with URIs.
4. Update the sample code – The sample projects don’t usually include storage handling, so you’ll need to add that yourself.
Android versions handle SD card access differently, so the exact solution depends a bit on which version you’re targeting. If you share that, I can help with more specific code examples. ameta community