【发布时间】:2011-11-09 04:38:52
【问题描述】:
我已经编写了自己的 ImageViewer,现在我想拥有像 Android 原生 ImageViewer 中的 Set as 功能。我现在有可能,因为 Facebook 有它。我附上了一个截图,让自己更清楚。
附:我想更详细地解释哪里出了问题。在我在菜单中选择“联系人图标”后,我的联系人列表就会出现。当我选择一个接触时,应用力关闭。如果我选择“主页/锁屏壁纸”,它会打开我手机的图库。 这是我的代码 sn-p:
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 卡。
【问题讨论】:
-
你必须发送一个意图。很简单。您所要做的就是搜索一些有关编辑联系人和以编程方式更改壁纸的代码
-
我找不到可以像在本机 ImageViewer 中一样打开 OptionsMenu 的代码。之后,当我选择一个动作时,它应该像原生一样继续。两者都比较容易做,但我不能做我需要的。
-
你能给我们一个logcat错误输出吗?
-
好的。我已将其添加到我的问题中。
-
你能把错误复制粘贴为文本吗?