0

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 Answers1

0

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"));
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Please explain your answer. SO exists not just to answer questions but to educate people – Machavity Nov 13 '15 at 00:11
  • Okay boss. so the drawable will take the whole imageview that you set the image previously. and then it will save into your gallery and then you can get the path from your local database and then you can take that image and share it and it same as like you share image from your phone gallery. – Andrew Indayang Nov 14 '15 at 11:19