与我的应用程序图标共享Android文本

Gia*_*cco 6 android share thumbnails

是否可以与我的应用程序图标共享文本?

在此输入图像描述

因为我试图这样做,但它适用于纯文本,但当我尝试使用图像时,它共享整个图像,但我只想要一个小缩略图.那是我的实际代码:

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"));
Run Code Online (Sandbox Code Playgroud)

Mik*_*nko 0

试试这个代码:

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"));
Run Code Online (Sandbox Code Playgroud)