sup*_*erM 6 android image viewer
我已经编写了自己的ImageViewer,现在我希望将Set设置为 Android原生ImageViewer中的功能.我现在有可能,因为Facebook有它.我附上了截图,让自己更加清晰.
PS我想更详细地解释出现了什么问题.在菜单中选择"联系人图标"后,将显示我的联系人列表.当我选择联系人时,申请人关闭.如果我选择"Home/Lock screen wallpaper",它会打开我手机的图库.这是我的代码片段:
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"));
Run Code Online (Sandbox Code Playgroud)
我还为我的清单添加了后续权限,我可以将我的图像写入手机的SD卡.

// Called when "Set as" is clicked.
private static boolean onSetAsClicked(MenuInvoker onInvoke,
final Activity activity) {
onInvoke.run(new MenuCallback() {
public void run(Uri u, IImage image) {
if (u == null || image == null) {
return;
}
Intent intent = Util.createSetAsIntent(image);
activity.startActivity(Intent.createChooser(intent,
activity.getText(R.string.setImage)));
}
});
return true;
}
Run Code Online (Sandbox Code Playgroud)
来自Utils.java
// Returns an intent which is used for "set as" menu items.
public static Intent createSetAsIntent(IImage image) {
Uri u = image.fullSizeImageUri();
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(u, image.getMimeType());
intent.putExtra("mimeType", image.getMimeType());
return intent;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6351 次 |
| 最近记录: |