【问题标题】:Android Intent with Gallery application to display images with a File ContentProvider带有 Gallery 应用程序的 Android Intent 使用 File ContentProvider 显示图像
【发布时间】:2012-11-21 23:01:19
【问题描述】:

我实现了一个文件 ContentProvider 以通过 http url 访问 wifi 网络上的文件服务器。

我要做的是启动具有特定意图和 uri 的 Android Gallery 应用程序,以显示位于我的文件服务器上特定目录中的图像文件。

如果我使用单个 uri 启动 Gallery 应用程序以通过此代码显示一张图像,我就能成功:

Intent lance = new Intent();
lance.setAction(Intent.ACTION_VIEW);
String typedata = "image/*";
lance.setType(typedata);
String phuri = "content://" + URI_AUTORITE
                     + "/" + URI_CONTENU_FICHIERS
                     + directory + filename;
Uri uri = Uri.parse(phuri);
lance.setDataAndType(uri, "image/*");
startActivity(lance);

但我试图更进一步来实现包含图像的目录的显示。我尝试使用 ClipData 对象显示几个图像,通过这段代码:

Intent lance = new Intent();
lance.setAction(Intent.ACTION_VIEW);
String typedata = "image/*";
lance.setType(typedata);
String phuri = "content://" + URI_AUTORITE
                     + "/" + URI_CONTENU_FICHIERS
                     + directory + filename;
Uri uri = Uri.parse(phuri);
ClipData ensemble = ClipData.newRawUri("Photos", uri);
lance.setClipData(ensemble);
startActivity(lance);

它不起作用:Gallery 应用程序启动并显示专辑列表并且不调用我的 File ContentProvider。

我错过了什么还是画廊应用程序开发人员有问题?

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    你应该重写你的内容提供者的 getType() 方法来返回像这样的 mime 类型的图像

    @Override
    public String getType(Uri uri) {
        return "image/*";
    }
    

    【讨论】:

    • 我的 getType 方法返回正确的字符串,但这还不够。画廊应用不会尝试读取剪辑数据的内容...
    • 您是否在内容提供者的清单文件中设置了exported=true?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 2017-06-12
    • 2017-03-21
    • 1970-01-01
    • 2018-03-05
    • 2014-07-31
    • 1970-01-01
    相关资源
    最近更新 更多