我想从一个 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/