从 URL 到浏览器或其他 Activity 的 Android Image Intent

标签 android android-intent

我想从一个 URL 到一个 Intent 打开一个图像,很可能是浏览器或者可能是像 twidroyd 内置的图片预览器。

Intent intent = new Intent();

Uri uri = Uri.parse("http://nssdc.gsfc.nasa.gov/image/planetary/earth/gal_new-zealand.jpg");

intent.setDataAndType(uri, "image/*");
intent.setAction(android.content.Intent.ACTION_GET_CONTENT);

startActivity(intent);

但是,当我尝试时,出现以下异常:

ERROR/AndroidRuntime(232): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT dat=http://nssdc.gsfc.nasa.gov/image/planetary/earth/gal_new-zealand.jpg typ=image/* }

我已经获得了可以在浏览器中打开的普通 URL。我只是不知道要指定什么操作或类别,我已经尝试过:

intent.addCategory("CATEGORY_BROWSABLE");
// and
intent.addCategory("CATEGORY_OPENABLE");

如果我将操作设置为:它也不起作用:

android.content.Intent.ACTION_VIEW

有什么想法吗?

最佳答案

根据浏览器如何设置其过滤器,设置 mime 类型可能会使 Intent 匹配器过于具体。尝试使用 ACTION_VIEW,将 uri 作为数据并且不设置 mime 类型。

关于从 URL 到浏览器或其他 Activity 的 Android Image Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3869509/

相关文章:

java - 为什么 JSON 响应是 200

Android 开发/调试最佳实践

android - 同时播放两种声音-Android

Android - 通知屏幕中的音乐播放器(顶部下拉屏幕)

android - 在 ListView 中启动 Activity

java - admob 和 startActivity 崩溃

c# - 如何处理 RadioGroup.SetOnCheckedChangeListener?

Android 不从内存中释放位图

即使操作系统杀死应用程序后,Android Activity 仍保留在堆栈中

java - 使用 Intent 打开 Waze GPS 导航或谷歌地图