首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Failed to attach.File not supported

Failed to attach.File not supported
EN

Stack Overflow用户
提问于 2015-03-28 10:48:35
回答 1查看 647关注 0票数 0

你好,我正在尝试发送照片与此代码,这似乎可以正常运行在whatsApp上,但每当我使用它与安卓本地消息应用程序,它说“附加图像失败;文件不支持”

从摄像头捕获图像后,我可以使用下面这行代码成功地将其保存在外部存储中:

代码语言:javascript
复制
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发送彩信:

代码语言:javascript
复制
    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);   
}
EN

回答 1

Stack Overflow用户

发布于 2015-11-13 07:36:12

试试那个。希望它能工作!!

代码语言:javascript
复制
 //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"));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29313094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档