我已经编写了自己的 ImageViewer,现在我想设置为功能。我现在有可能,因为 Facebook 有它。我附上了一个截图,让自己更清楚。
PS我想更详细地解释出了什么问题。在我在菜单中选择“联系人图标”后,我的联系人列表就会出现。当我选择一个接触时,应用力关闭。如果我选择“主页/锁屏壁纸”,它会打开我手机的图库。这是我的代码片段:
Bitmap icon = mBitmap;
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.setType("image/jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "/my_tmp_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
setAs.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/my_tmp_file.jpg"));
startActivity(Intent.createChooser(setAs, "Set Image As"));
我还在清单中添加了相应的权限,并且可以将图像写入手机的 SD 卡。