【问题标题】:Is there a native photo viewer?有本地照片查看器吗?
【发布时间】:2012-08-28 13:55:40
【问题描述】:
我正在为 Android ICS 构建相机和图库应用。我有一个图库视图和相机工作,但现在想添加从图库中单击图像并使用标准缩放手势等使该照片全屏显示的功能。不确定这是否是我必须从头开始编写的东西,或者如果已经有一个本地 ICS 照片查看器,我也可以通过意图附加功能或其他东西传递文件.. 无论哪种方式.. 有人可以给我指一个在线示例?
【问题讨论】:
标签:
android
android-intent
photo
android-imageview
android-gallery
【解决方案1】:
您可以使用Intent.ACTION_VIEW 和指向照片位置的Url 对象启动手机的照片查看器。见Start an Activity with the Intent。
// Build the intent
Intent photoIntent = new Intent(Intent.ACTION_VIEW);
photoIntent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(photoIntent, 0);
boolean isIntentSafe = activities.size() > 0;
// Start an activity if it's safe
if (isIntentSafe) {
startActivity(photoIntent);
}