"Sharing internal / cache images (with text) to other Android apps" (tutorial at https://blog.jakelee.co.uk/sharing-internal-cache-images-with-text-to-other-android-apps)
This file contains 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:grantUriPermissions="true" | |
| android:exported="false"> | |
| <meta-data | |
| android:name="android.support.FILE_PROVIDER_PATHS" | |
| android:resource="@xml/filepaths" /> | |
| </provider> |
This file contains 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> | |
| <cache-path name="shared_images" path="/images/"/> | |
| </paths> |
This file contains 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
| fun shareImage(file: File) { | |
| val authority = "${BuildConfig.APPLICATION_ID}.fileprovider" | |
| FileProvider.getUriForFile(context, authority, file)?.let { | |
| val shareIntent = Intent() | |
| .setAction(Intent.ACTION_SEND) | |
| .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | |
| .setDataAndType(it, context.contentResolver.getType(it)) | |
| .putExtra(Intent.EXTRA_STREAM, it) | |
| .putExtra(Intent.EXTRA_TEXT, "I'm sharing this image!") | |
| context.startActivity(Intent.createChooser(shareIntent, "Share image to:")) | |
| } | |
| } | |
| val imageCache = File(context.cacheDir, "images") | |
| shareImage(File(imageCache, "myimage.png")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment