我实现了一个文件ContentProvider,通过http访问wifi网络上的文件服务器。
我尝试做的是启动Android Gallery应用程序,并使用特定的意图和uri来显示位于我的文件服务器上的特定目录中的图像文件。
如果我使用单个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);它不起作用:画廊应用程序启动,并显示专辑列表,但不调用我的文件ContentProvider。
是我错过了什么,还是Gallery应用程序开发人员遇到了问题?
发布于 2012-11-21 23:01:19
您应该重写内容提供者的getType()方法来返回mime类型的图像,如下所示
@Override
public String getType(Uri uri) {
return "image/*";
}https://stackoverflow.com/questions/12652376
复制相似问题