无法附加。文件不受支持

时间:2015-03-28 02:48:35

标签: android sms android-mms

您好我正在尝试使用此代码发送照片,该代码似乎可以在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);   
}

1 个答案:

答案 0 :(得分: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"));