Failed to attach.File not supported

816 Views Asked by At

Hello I am trying to send photo with this code which seems to be run on whatsApp properly but whenever I use it with android native messaging app it says "Attaching image failed;file not supported"

After capturing image from camera I am able to save it successfully in the external storage with this line of code:

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

In mcurrentPath I saved the path to the image file and then I used this as uri in the code below to send 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);   
}
1

There are 1 best solutions below

2
On

TRY that one. hopefully it works!!

 //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"));