Created
September 7, 2025 10:55
-
-
Save root-ansh/8c84daacc202f8a667f4adc3433b4571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <provider | |
| android:name="androidx.core.content.FileProvider" | |
| android:authorities="${applicationId}.fileprovider" | |
| android:exported="false" | |
| android:grantUriPermissions="true"> | |
| <meta-data | |
| android:name="android.support.FILE_PROVIDER_PATHS" | |
| android:resource="@xml/file_paths" /> | |
| </provider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <paths xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <!-- for sharing files that are present in context.cachDir --> | |
| <cache-path | |
| name="shared_cache" | |
| path="." /> | |
| </paths> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun shareMedia(shareType: RWSMediaType) { | |
| val context = this | |
| when(shareType){ | |
| IMAGE -> { | |
| lifecycleScope.launch { | |
| val cachePath = File(context.cacheDir, "images") | |
| cachePath.mkdirs() | |
| val file = File(cachePath, "${System.currentTimeMillis()}.png") | |
| val bitmap = getCurrentImageViewBitmap() | |
| context.saveBitmapToUserSelectedPath(Uri.fromFile(file),bitmap)// convert bitmap to local cache file first | |
| context.shareLocalFile(file) | |
| } | |
| } | |
| PDF ,FILE -> { | |
| val file = if(shareType==PDF) state.pdfFile!! else state.mediaFile!! | |
| context.shareLocalFile(file) | |
| } | |
| } | |
| } | |
| fun Context.shareLocalFile(file: File) { | |
| val context = this | |
| val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.extension.lowercase()) ?: "application/octet-stream" | |
| val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file) | |
| val shareIntent = Intent(Intent.ACTION_SEND).apply { | |
| type = mimeType | |
| putExtra(Intent.EXTRA_STREAM, uri) | |
| addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | |
| } | |
| context.startActivity( | |
| Intent.createChooser(shareIntent, "Share file via") | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment