you have to write a caption on the image and then create a uri.
private Bitmap writeTextOnDrawable(int drawableId, String text) { Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Typeface tf = Typeface.create("Helvetica", Typeface.BOLD); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.WHITE); paint.setTypeface(tf); paint.setTextAlign(Align.CENTER); paint.setTextSize(convertToPixels(mContext, 11)); Rect textRect = new Rect(); paint.getTextBounds(text, 0, text.length(), textRect); Canvas canvas = new Canvas(bm);
ref: Add text to a file in Android software
Save bitmap to file:
Save bitmap in file function
create uri from file:
Uri.fromFile(new File(<your image absolute path>));
Then pass this uri to your function
private void shareInstagram(Uri uri){ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); // set mime type shareIntent.putExtra(Intent.EXTRA_STREAM,uri); // set uri shareIntent.putExtra(Intent.EXTRA_TITLE, "Sample title"); shareIntent.setPackage("com.instagram.android"); startActivity(shareIntent); }
Hope it should work
source share