Sharing Android text with my app icon

Can I share text with a similar icon in my application?

enter image description here

Because I'm trying to do this, but it works with plain text, but when I try with the image, it shares the whole image, but I just want a slightly smaller image. This is my actual code:

Intent intent2=new Intent(Intent.ACTION_SEND); intent2.setType("image/*"); intent2.putExtra(Intent.EXTRA_TEXT,random); Uri path = Uri.fromFile(new File(Image)); intent2.putExtra(Intent.EXTRA_STREAM, path ); startActivity(Intent.createChooser(intent2, "Share via")); 
+5
source share
1 answer

try this code:

 Bitmap icon = mBitmap; 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_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg")); startActivity(Intent.createChooser(share, "Share Image")); 
0
source

Source: https://habr.com/ru/post/1207798/


All Articles