你好,我正在尝试发送照片与此代码,这似乎可以正常运行在whatsApp上,但每当我使用它与安卓本地消息应用程序,它说“附加图像失败;文件不支持”
从摄像头捕获图像后,我可以使用下面这行代码成功地将其保存在外部存储中:
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发送彩信:
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);
}发布于 2015-11-13 07:36:12
试试那个。希望它能工作!!
//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"));https://stackoverflow.com/questions/29313094
复制相似问题