Share An Image Without Saving it in Android

As a matter of fact sometimes we want to share images without saving it. Images from internet or locally generated images.For example  whatsapp profile pictures. You can share it, but it’s only visible in gallery when we saved it. However we are using bitmap generated from linear-layout to share.

In fact  sharing an image without saving it is by using cache memory. Consequently we can share it like an uri. On the other hand we can simply store the image in cache and use the uri for sharing.



share-image-without-saving logicchip 1

Furthermore we are saving bitmap to cache and use it for sharing. In fact a previous post explain how to convert view to bitmap.Binary data is shared using the ACTION_SEND action combined with setting the appropriate MIME type and placing the URI to the data in an extra named EXTRA_STREAM. This is commonly used to share an image but can be used to share any type of binary content.

You can use a MIME type of "*/*", but this will only match activities that are able to handle generic data streams.

In conclusion the receiving application needs permission to access the data the Uri points to.

Similarly we don’t need any special permission to store data in cache memory.

Adding Permission

Add these permissions in the manifest file.

OnClickShare

However below is the onclick method for share button. Create a method with view as argument then specify it in the xml file.




Creating bitmap from view

For instance method creates bitmap from view or any layout extending view.If the background is empty it set’s white color as background.

MainActivity.java

This class file contain both methods, we don’t use onclick listener or implement onclick listener in order to reduce code. Because the click is coded directly to the xml file using onclick.

activity_main.xml

Still the  project require an user interface. Even though below xml file is just for showing how this work.

Even so “Share An Image Without Saving it in Android” is explained above you can still download it from here, You can modify the code us u like. In like manner feel free to comment your doubt’s below. Does our tutorials help you then help as spread the word, like and share.

 

4 thoughts on “Share An Image Without Saving it in Android

Leave a Reply

%d bloggers like this: