0

您好,我正在尝试使用此代码发送照片,该代码似乎可以在 WhatsApp 上正确运行,但每当我将它与 android 本机消息传递应用程序一起使用时,它都会显示“附加图像失败;不支持文件”

从相机捕获图像后,我可以使用以下代码将其成功保存在外部存储中:

private File createImageFile() throws IOException {
    String imageFileName = "imagex";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

在 mcurrentPath 中,我保存了图像文件的路径,然后在下面的代码中将其用作 uri 来发送 mms:

    private void sendme() {
    String imageFileName = "imagex.jpg";
    //File storageDir = Environment.getExternalStoragePublicDirectory(
      //      Environment.DIRECTORY_PICTURES);
    //File image =new File(storageDir,imageFileName);
    String path=mCurrentPhotoPath;
    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra("address","9982347135");
    i.putExtra("sms_body","body");
    i.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));
    i.setType("image/*");
    startActivity(i);   
}
4

1 回答 1

0

试试那个。希望它有效!

 //itemImage from the imageview
    Drawable mDrawable = itemImage.getDrawable();
    Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
    String path = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), mBitmap, "Image Description", null);
    Uri uri = Uri.parse(path);

    //text from CMS
    String shareText = game.getEnding_share_txt();

    //share using intent
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, uri);

    intent.setType("text/plain");
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(intent, "Share with"));
于 2015-11-12T23:36:11.513 回答