Skip to main content
New Participant
September 19, 2025
Solved

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.

 

This topic has been closed for replies.
New Participant
September 19, 2025

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

4 replies

88TianAuthor
New Participant
September 19, 2025

add my quest3 version information:

[ro.build.version.sdk]: [34]

[ro.build.version.security_patch]: [2025-01-06]

[ro.kernel.version]: [5.10]

[ro.odm.build.version.incremental]: [51154110174900520]

[ro.odm_dlkm.build.version.incremental]: [51154110174900520]

[ro.odm_dlkm.build.version.release]: [14]

[ro.odm_dlkm.build.version.release_or_codename]: [14]

[ro.odm_dlkm.build.version.sdk]: [34]

[ro.opengles.version]: [196610]

[ro.ovr.os.api.version]: [160]

[ro.product.build.version.incremental]: [51154110174900520]

[ro.product.build.version.release]: [14]

[ro.product.build.version.release_or_codename]: [14]

[ro.product.build.version.sdk]: [34]

[ro.product.vndk.version]: [34]

[ro.property_service.version]: [2]

[ro.system.build.version.incremental]: [51154110174900520]

[ro.system.build.version.release]: [14]

[ro.system.build.version.release_or_codename]: [14]

[ro.system.build.version.sdk]: [34]

[ro.system_ext.build.version.incremental]: [51154110174900520]

[ro.system_ext.build.version.release]: [14]

[ro.system_ext.build.version.release_or_codename]: [14]

[ro.system_ext.build.version.sdk]: [34]

[ro.vendor.build.version.incremental]: [51154110174900520]

[ro.vendor.build.version.release]: [14]

[ro.vendor.build.version.release_or_codename]: [14]

[ro.vendor.build.version.sdk]: [34]

[ro.vendor_dlkm.build.version.incremental]: [51154110174900520]

[ro.vendor_dlkm.build.version.release]: [14]

[ro.vendor_dlkm.build.version.release_or_codename]: [14]

[ro.vendor_dlkm.build.version.sdk]: [34]

[ro.vndk.version]: [34]

[ro.vros.build.version]: [79]

Participant
September 19, 2025

On newer Android versions, MANAGE_EXTERNAL_STORAGE alone won’t grant access—apps targeting Android 11+ need to use the Storage Access Framework or scoped storage APIs. Direct /sdcard/ access is restricted, so you’ll likely need to request file access through ACTION_OPEN_DOCUMENT or use MediaStore for videos

New Participant
September 19, 2025

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. For more: ameta community.

New Participant
September 19, 2025

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