I want to ‘open with’ my application when user wants to open pdf, so I added intent filters in manifest xml and created +native-intent.ts
to get pdf path in FileProvider. It works when opening from ‘My Files’ which is default native file manager in Android.
But When I open the file from other apps, like Kakaotalk or Slack, and copy that content://
file into file://
which is in cache directory, the error below occurs.
I tried to make native module to call currentActivity.grantUriPermission(currentActivity.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
, but it did not work (java.lang.SecurityException: UID 10874 does not have permission to content)
code where error occured
async function copySharedPathToUri(contentUri: string) {
const destinationUri = FileSystem.cacheDirectory + "tempFile";
await FileSystem.copyAsync({
from: contentUri,
to: destinationUri,
});
return destinationUri;
}
error
Error uploading file: [Error: Call to function 'ExponentFileSystem.copyAsync' has been rejected.
→ Caused by: java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.kakao.talk.FileProvider/external_files/emulated/0/Android/data/com.kakao.talk/contents/MTg=/2412.10468v1.pdf from pid=25200, uid=10858 requires the provider be exported, or grantUriPermission()]
+native-intent.ts
export function redirectSystemPath({
path,
initial,
}: {
path: string;
initial: string;
}) {
try {
console.log("redirectSystemPath", path, initial);
return `/?sharedPath=${encodeURIComponent(path)}`;
} catch {
return "/";
}
}
These are dependencies
"dependencies": {
"@expo-google-fonts/inter": "^0.2.3",
"@expo/vector-icons": "^14.0.2",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-navigation/native": "^7.0.0",
"axios": "^1.7.7",
"cookie": "^1.0.1",
"date-fns": "^4.1.0",
"expo": "~52.0.19",
"expo-apple-authentication": "~7.1.2",
"expo-build-properties": "~0.13.1",
"expo-constants": "~17.0.3",
"expo-dev-client": "~5.0.6",
"expo-document-picker": "~13.0.1",
"expo-file-system": "~18.0.6",
"expo-font": "~13.0.1",
"expo-image": "~2.0.3",
"expo-linking": "~7.0.3",
"expo-router": "~4.0.13",
"expo-share-intent": "^3.1.1",
"expo-splash-screen": "~0.29.18",
"expo-status-bar": "~2.0.0",
"expo-system-ui": "~4.0.6",
"expo-web-browser": "~14.0.1",
"nativewind": "^4.1.23",
"patch-package": "^8.0.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.76.5",
"react-native-gesture-handler": "~2.20.2",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "^4.0.0",
"react-native-web": "~0.19.10",
"react-native-webview": "13.12.5",
"tailwindcss": "^3.4.14"
},
And here is part of xml
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="moonlight"/>
<data android:scheme="com.corca.moonlight"/>
<data android:scheme="exp+moonlight"/>
</intent-filter>
Already spent more than 24 hours, please help me 🙂
May be you can try ask permission
const downloadsUri =
FileSystem.StorageAccessFramework.getUriForDirectoryInRoot(‘directory you need’)
const permissions =
await FileSystem.StorageAccessFramework.requestDirectoryPermissionsAsync(
downloadsUri
)
Oleg Kuzmin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.