How to share specific 1 card view of activity from Android App programmatically like Google Analytics App
How to share specific 1 card view of activity from Android App programmatically like Google Analytics App
I am working on an android app of social network and i am stuck at one place.
I want to share specific card view from an activity to facebook or whatsapp wherever user wants to share as an image like google analytics app.
check screenshot below

Suppose i want to share top 2 card then i can share like this to whatsapp or fb whever i want
First i thought to take screenshot of app and share it to user's social app but it doesn't match to requirements and i have no idea how can we achieve this.
Help me to solve this problem.
3 Answers
3
You cannot share a 'Card' to other Apps, however you share a Bitmap (Screenshot) of the Card...
Here's how to do it -
Create a method like below -
public Bitmap ViewShot(View v)
int height = v.getHeight();
int width = v.getWidth();
Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas (b);
v.layout(0, 0 , v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
Pass the CardView in the View parameter of ViewShot like -
Bitmap screenshot = ViewShot(myCardView);
Now you can save that Bitmap to a Temp file & share it with other app!
when i pass my cardview in method it sayt width and height cannot be 0 !!
– chirag patel
Sep 10 '18 at 8:54
@chiragpatel please share cardview layout or try setting height & width explicitly & not as wrap content!
– DarShan
Sep 10 '18 at 14:51
Create an image and sent it via intent. An easy way to create a bitmap of a view is to create a bitmap object with width and height equal to that of the view, create a Canvas for that bitmap, and call the view's onDraw function passing in that Canvas. That will make the View draw itself to the Bitmap.
If you want to share specific data of that card, my suggestion is Firebase Dynamic Links. I think this is what you are looking for. You can create a dynamic link for specific page of your app and share the link via whatever you want.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
take screenshot of view and share this bitmap using intent.
– Nouman Ch
Sep 6 '18 at 6:01