如何使用“共享图像使用”共享意图共享图像在Android?我有图像厨房的应用程序,我把所有的图像放在绘图-hdpi文件夹。在我的活动中,我把图像叫做:private Integer[] imageIDs = {
R.drawable.wall1, R.drawable.wall2,
R.drawable.wall3, R.drawable.wall4,
R.drawable.wall5, R.drawable.wall6,
R.drawable.wall7, R.drawable.wall8,
R.drawable.wall9, R.drawable.wall10};因此,现在我想知道如何使用共享意图共享这些图像,我提供了这样的共享代码: Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});我也有分享按钮,当我点击共享按钮共享框打开,但当我剪裁任何服务,大部分是它的崩溃或一些服务说:无法打开图像,所以我如何能够修复这个,或者有任何格式代码来共享图像?编辑:我试过使用下面的代码。但这不起作用。Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.android.test/*");
try {
InputStream stream = getContentResolver().openInputStream(screenshotUri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});如果不介意的话,请更正我上面的代码,或者给我一个适当的示例plz,我如何共享可绘制-hdpi文件夹中的图像?
3 回答
RISEBY
TA贡献1856条经验 获得超5个赞
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"));
- 3 回答
- 0 关注
- 406 浏览
添加回答
举报
0/150
提交
取消