You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While sharing a document to various apps (e.g., Telegram, WhatsApp, etc.), everything worked as expected. However, when using my app, which integrates the share_handler SDK, the file path received was invalid and inaccessible. An example of the problematic file path was: /storage/emulated/0/Android/data/my_org/files/Documents/AppFromWhereIShare/All/mic_20241213-180404.amr
I was managed to fix it by applying following changes to FileDirectory
...
if (isExternalStorageDocument(uri)) {
return getCachedDocumentPath(context, uri)
}
...
/**
* Copies the file referenced by the URI to the cache directory and returns its path.
*
* @param context The context.
* @param uri The Uri to copy.
*/
private fun getCachedDocumentPath(context: Context, uri: Uri): String? {
val fileName = uri.lastPathSegment?.split("/")?.lastOrNull() ?: "temp_${System.currentTimeMillis()}"
val tempFile = File(context.cacheDir, fileName)
return try {
context.contentResolver.openInputStream(uri)?.use { input ->
FileOutputStream(tempFile).use { output ->
input.copyTo(output)
}
}
Log.i("FileDirectory", "File copied to temp: ${tempFile.absolutePath}")
tempFile.absolutePath
} catch (e: Exception) {
Log.e("FileDirectory", "Failed to copy file to temp: ${e.localizedMessage}")
null
}
}
Please consider applying this change or suggest an alternative solution to resolve the issue.
The text was updated successfully, but these errors were encountered:
https://github.com/ShoutSocial/share_handler/blob/b0f0a7a243786d526ed7f8beee11fdf61ed2e9da/share_handler_android/android/src/main/kotlin/com/shoutsocial/share_handler/FileDirectory.kt#L34C1-L42C18
While sharing a document to various apps (e.g., Telegram, WhatsApp, etc.), everything worked as expected. However, when using my app, which integrates the share_handler SDK, the file path received was invalid and inaccessible. An example of the problematic file path was:
/storage/emulated/0/Android/data/my_org/files/Documents/AppFromWhereIShare/All/mic_20241213-180404.amr
I was managed to fix it by applying following changes to FileDirectory
Please consider applying this change or suggest an alternative solution to resolve the issue.
The text was updated successfully, but these errors were encountered: