How to create the 'Share to' popup in Android using share intent?
Providing the option for users to share data from your app to another app is very useful. This feature maybe used just to share the install link of your app for reference credits or just for social sharing.
Google provides a very simple method of sharing data to other apps. This is using the Share Intent. Below shows the use of share intent, where a text and an image are shared:
File file = new File(getActivity().getCacheDir(), "app_promo.png"); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out this awesome app"); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); sendIntent.setType("image/*"); context.startActivity(Intent.createChooser(sendIntent, "Share to:"));
If you use the above code in the OnClickListener of the Share button, you will have implemented the Share feature in your app. Yes, it is as simple as that