当我尝试使用意图获取消息"Sorry we couldn't load your photo"
我使用以下代码,
Uri imageUri = Uri.parse("android.resource://"+getPackageName()+"/drawable/"+filename);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpg");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent , "Share"));
当我尝试通过Gmail发送时,没有附件。 我可以知道是什么原因吗?
答案 0 :(得分:1)
某些应用程序(如Gmail,Facebook,Google Plus ......)无法附加照片,因为您的 imageUri 是私密的。
您应该将drawable保存到图库或公用文件夹,然后获取要分享的newImageUri。
intent.putExtra(Intent.EXTRA_STREAM, newImageUri);
答案 1 :(得分:0)
public void shareImage()
{
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));
}