In my project sharing only text and if only image in post not sharing anything.. what i need to do?
Android Studio 3: Combine Image and Text of Post to share on Whatsapp?
Below is the function of implementation.
public void postShare(Item item) {
String shareText = "";
if (item.getPost().length() > 0) {
shareText = item.getPost();
} else {
if (item.getImgUrl() == null || item.getImgUrl().length() == 0) {
shareText = item.getLink();
}
}
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) context.getString(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
if ((item.getImgUrl().length() > 0) && (ContextCompat.checkSelfPermission(this.context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
ImageView image;
ImageLoader imageLoader = App.getInstance().getImageLoader();
image = new ImageView(context);
if (imageLoader == null) {
imageLoader = App.getInstance().getImageLoader();
}
imageLoader.get(item.getImgUrl(), ImageLoader.getImageListener(image, R.drawable.profile_default_photo, R.drawable.profile_default_photo));
Drawable mDrawable = image.getDrawable();
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), mBitmap, "Image Description", null);
Uri uri = Uri.parse(path);
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
}
shareIntent.setType("text/plain");
context.startActivity(Intent.createChooser(shareIntent, "Share post"));
}