Is it possible to share an image on Android via a data URL?
android, android-intent, graphics, java
Solution
Is it possible to share an image with code something like this?
No, because `ACTION_SEND` does not use the `Uri`. It uses `EXTRA_TEXT` or `EXTRA_STREAM`.
My goal is to make my app not require permissions to write to storage, but to be able to share images that it dynamically creates. Is there any way to do this?
Create a `ContentProvider` to serve the file, then put the `Uri` pointing to your file within your provider in `EXTRA_STREAM`. You may be able to protect the provider with a custom permission and allow the sending activity temporary access to it via `FLAG_GRANT_READ_URI_PERMISSION`, though I have only tried that with `Intent` structures that use the actual `Uri` (e.g., `setData()`) instead of via an extra like `EXTRA_STREAM`.
This sample project demonstrates this technique using `ACTION_VIEW` (note: requires a device with a PDF viewer installed to truly work).
Problem
Is it possible to share an image with code something like this? ``` Intent share = new Intent(Intent.ACTION_SEND); share.setData(Uri.parse("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACx" + "jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGoSURBVDhPlVM9SEJRGD2DkL+QmoiKYNggToJL" + "4KKLNDiKW4NCoENQkzS1uboILoKjW61NSZOjo1uOBlHPgjJsuN3jvc+naVQHPt79vu+cc9/37n34" + "BQkd/0Jibw+3Ozt4j0TwwuCaNfYU5Qe43Tg5OMDD9TWEYUAIoYJr1mIxPEmjc01fh8uF03wer6vC" + "7zGbQZRKmPp8uNCyJWKhEAwSTDJ3NNc07fUsE76J1FjjcL5VQb0O4XBAVCoqj0ZV3u2qvN+H8Psx" + "1HLAZsPn6u6pFIQsi3AYYjKBcDpVXiyqPrl2O2ayZqc+FY9jaooZuZwSJBJL8iKv1SwONdTSIJtO" + "w1g1GA4h9vfVk3mjod5mPLY4ySQMqT2kgZ0jsMjZBgOL9D1omM2qtfwmH1K7SwN4vbhnkzuQ0G5v" + "imnOHjkMjwePC7HGUSajxuDM1aqa/+wM4vJSCRnmHSkU8CwNjrVWIRDAVauFubnjaATRbCoD7m7W" + "Ox3Mg0HcaNkaduV9GPCmbbuNrLEnxXeSuzi+reD/wJ+Hx1Qu443BNWvsadqfwDOu6lic9yaAL2uK" + "Y4RMd4E2AAAAAElFTkSuQmCC")); startActivity(Intent.createChooser(share, getString(R.id.menu_share))); ``` My goal is to make my app not require permissions to write to storage, but to be able to share images that it dynamically creates. Is there any way to do this?