Java 在android上同时共享图像和文本不适用于电报

Java 在android上同时共享图像和文本不适用于电报,java,android,share,telegram,Java,Android,Share,Telegram,我正在使用下面的代码在Android中共享图像和文本。当我选择Whatsapp时,它会同时共享图像和文本,但当我选择Telegram时,它只共享图像而不共享任何文本!我的代码出了什么问题?Tnx BitmapDrawable drawable = (BitmapDrawable) imageViewSample .getDrawable(); Bitmap bitmapImg = drawable.getBitmap(); ByteArrayOutputStream by

我正在使用下面的代码在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();
 }

使用作为参数传递的路径创建一个新文件,然后使用类Uri(统一资源标识符)中的方法“fromFile(File name)”,并像往常一样继续执行代码

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();
      }

它起作用了。看看我的代码:

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.setType("image/*");
    sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.insta_image_j);
    Bitmap bitmapImg = drawable.getBitmap();

    sharingIntent.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmapImg, context));
    sharingIntent.putExtra(
            android.content.Intent.EXTRA_TEXT,
            context.getString(R.string.share_text));
    sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(Intent.createChooser(sharingIntent, context.getResources().getString(R.string.share_using)));
我在应用程序的onCreate()中添加了以下行:

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());