Is it possible to share an image on Android via a data URL?

谁都会走 提交于 2019-12-23 12:18:34

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/15851681/is-it-possible-to-share-an-image-on-android-via-a-data-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!