Created
November 28, 2016 11:51
-
-
Save mahdimortazavi/e54bc60b4ba58e69a2d8cc827260bb63 to your computer and use it in GitHub Desktop.
share image and text from app to telegram or other application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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