Skip to content

Instantly share code, notes, and snippets.

@mahdimortazavi
Created November 28, 2016 11:51
Show Gist options
  • Save mahdimortazavi/e54bc60b4ba58e69a2d8cc827260bb63 to your computer and use it in GitHub Desktop.
Save mahdimortazavi/e54bc60b4ba58e69a2d8cc827260bb63 to your computer and use it in GitHub Desktop.
share image and text from app to telegram or other application
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_TEXT, "hello #test");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment