private void shareApp() {
String packageName = getPackageName();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check out this app: https://play.google.com/store/apps/details?id=" + packageName);
Intent chooserIntent = Intent.createChooser(shareIntent, "Share this app");
PackageManager packageManager = getPackageManager();
if (chooserIntent.resolveActivity(packageManager) != null) {
Drawable appIcon = null;
try {
appIcon = packageManager.getApplicationIcon(packageName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (appIcon != null) {
Bitmap appBitmap = ((BitmapDrawable) appIcon).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
appBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] appIconData = stream.toByteArray();
chooserIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), appBitmap, "App Icon", null)));
chooserIntent.setType("image/png");
}
}
startActivity(chooserIntent);
}