ACTION_SEND 发送图片

用ACTION_SEND 发送图片如果 i.setType("image/jpeg");
                i.putExtra(Intent.EXTRA_STREAM, Img.getThumbFileUri());
                MyMv.getContext().startActivity(Intent.createChooser(i,"Send Image To:"));

一定会提示错误解决办法 必须将这个图片找个地方保存,然后用uri的形式读取出来,这里有两种办法

第一种就是将图片插入到gally中:

File imageFile = new File(Constants.SYSTEM_DYNOMASTER_DIR,filename);
FileOutputStream fout = new FileOutputStream(imageFile);
blankBitmap.compress(CompressFormat.JPEG, 100, fout);
fout.flush();
fout.close();

String url = Media.insertImage(context.getContentResolver(), imageFile.getAbsolutePath(), imageFile.getName(), imageFile.getName());

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(Intent.EXTRA_TEXT, body);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/jpeg");
context.startActivity(shareIntent);

 

第二种保存在其他地方:

FileOutputStream Os = getAppContext().openFileOutput("Img" + _PicId + ".jpg", Context.MODE_WORLD_READABLE);
Bm.compress(Bitmap.CompressFormat.JPEG, 100, Os);
Os.close();

 

然后

File F = getAppContext().getFileStreamPath("Img" + _PicId + ".jpg");
                Uri U = Uri.fromFile(F);

                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("image/jpg");
                i.putExtra(Intent.EXTRA_STREAM, U);
                getContext().startActivity(Intent.createChooser(i,"Send Image To:"));<!-- / message --><!-- old edit msg spot --><!-- old edit msg spot -->

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值