【问题标题】:Android Image Intent from URL to Browser or other activity从 URL 到浏览器或其他活动的 Android 图像意图
【发布时间】:2010-10-06 13:26:10
【问题描述】:

我想从一个 URL 打开一个图像到一个意图,很可能是浏览器或者像 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);

但是当我尝试时,我得到以下异常:

错误/AndroidRuntime(232): android.content.ActivityNotFoundException: 未找到处理 Intent { 的活动 act=android.intent.action.GET_CONTENT dat=http://nssdc.gsfc.nasa.gov/image/planetary/earth/gal_new-zealand.jpg 类型=图像/* }

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

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

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

android.content.Intent.ACTION_VIEW

有什么想法吗?

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    根据浏览器设置过滤器的方式,设置 mime 类型可能会使 Intent 匹配器过于具体。尝试使用ACTION_VIEW,将uri作为数据,不要设置mime类型。

    【讨论】:

    • 我应该坚持做我为其他网址所做的事情。我想也许图像会被特殊处理。谢谢!
    猜你喜欢
    • 2016-01-09
    • 2012-03-29
    • 2015-04-11
    • 1970-01-01
    • 2013-07-13
    • 2012-05-17
    • 1970-01-01
    • 2022-06-15
    • 2017-06-11
    相关资源
    最近更新 更多