一起共享图像和文本不适用于 android 上的 Telegram

Ami*_*min 5 java android share telegram

我正在使用下面的代码在 Android 中共享图像和文本。当我选择 Whatsapp 时,它会将图像和文本一起共享,但是当我选择 Telegram 时,它只共享图像而没有任何文本!我的代码有什么问题?Tnx

    BitmapDrawable drawable = (BitmapDrawable) imageViewSample .getDrawable();
    Bitmap bitmapImg = drawable.getBitmap();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    bitmapImg.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = Images.Media.insertImage(getContext() .getContentResolver(), bitmapImg, "Title", null);
    Uri myUri= Uri.parse(path);
        try {
            Intent share = new Intent(Intent.ACTION_SEND);                            
            share.putExtra(Intent.EXTRA_STREAM , myUri);
            myBodyText="This is a test.";
            share.putExtra(Intent.EXTRA_TEXT , myBodyText);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            share.setType("image/*");
            startActivity(Intent.createChooser(share, "choose app"));
       } catch (Exception e) {
            e.printStackTrace();
 }
Run Code Online (Sandbox Code Playgroud)

小智 0

创建一个新文件,并将您的 PATH 作为参数传递,然后使用 Uri(统一资源标识符)类中的方法“fromFile(文件名)”并照常继续处理您的代码。

BitmapDrawable drawable = (BitmapDrawable) imageViewSample .getDrawable();
Bitmap bitmapImg = drawable.getBitmap();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmapImg.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(getContext() .getContentResolver(),bitmapImg, "Title", null);
File myImage = new File(path); // introduce the new File
Uri myUri= Uri.fromFile(myImage); //Pass the file as argument
  try {
        Intent share = new Intent(Intent.ACTION_SEND);                            
        share.putExtra(Intent.EXTRA_STREAM , myUri);
        myBodyText="This is a test.";
        share.putExtra(Intent.EXTRA_TEXT , myBodyText);
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        share.setType("image/*");
        startActivity(Intent.createChooser(share, "choose app"));
      } catch (Exception e) {
        e.printStackTrace();
      }
Run Code Online (Sandbox Code Playgroud)