我正在尝试做一个小应用程序,它只显示画廊视图中特定文件夹中的图像。
Uri targetUri = Media.EXTERNAL_CONTENT_URI;
String folderPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/";
int folderBucketId = folderPath.toLowerCase().hashCode();
targetUri = targetUri.buildUpon().appendQueryParameter("bucketId", String.valueOf(folderBucketId)).build();在initializeDataSource()中
// Creating the DataSource objects.
final LocalDataSource localDataSource = new LocalDataSource(Gallery.this, targetUri.toString(), false);但我错了
"Error finding album " + bucketId);在CacheService.loadMediaSets.中
Log.e(TAG, "Error finding album " + bucketId);我该如何解决这个问题呢?谢谢你
发布于 2013-03-24 14:51:08
“错误查找相册”的问题很可能是因为在代码中获取bucketId的"DCIM“文件夹中没有直接包含任何图像。例如,如果你使用"/DCIM/Camera“代替(假设有一些图像),你应该不会得到错误。
但是,如果我正确理解了您想要什么,我相信您需要对Gallery3D代码进行额外的修改,以使它在启动时显示一个特定的文件夹(因为代码不是被设计成这样使用的)。
与使用上面的代码相比,我相信通过将意图设置为onCreate()中的特定意图,您可以更容易地实现您想要的内容
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setIntentToSpecificFolder();
mApp = new App(Gallery.this);
// :
// the rest of onCreate() code
// :
Log.i(TAG, "onCreate");
}
private void setIntentToSpecificFolder() {
String folderPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera";
int folderBucketId = folderPath.toLowerCase().hashCode();
Uri targetUri = Media.EXTERNAL_CONTENT_URI.buildUpon().appendQueryParameter("bucketId", String.valueOf(folderBucketId)).build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "vnd.android.cursor.dir/image");
setIntent(intent);
}基本上,我们在这里所做的是,当应用程序与vnd.android.cursor.dir/image MIME类型一起提供时,利用应用程序的ACTION_VIEW意图处理。
发布于 2013-03-24 17:55:37
假设您需要查找某个文件夹下的文件路径。
private String[] mFileStrings;
private File[] listFile;
public void getFromSdcard()
{
File file= new File(android.os.Environment.getExternalStorageDirectory(),"Your Folder Name");
if (file.isDirectory())
{
listFile = file.listFiles();
mFileStrings = new String[listFile.length];
for (int i = 0; i < listFile.length; i++)
{
mFileStrings[i] = listFile[i].getAbsolutePath();
System.out.println("...................................."+mFileStrings[i]);
}
}
}在我的手机里,我的内存被命名为sdcard0。所以为了确保你得到正确的路径,你可以使用下面的代码。
String externalpath = new String();
String internalpath = new String();
public void getExternalMounts() {
Runtime runtime = Runtime.getRuntime();
try
{
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;
if (line.contains("fat")) {//external card
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
externalpath = externalpath.concat("*" + columns[1] + "\n");
}
}
else if (line.contains("fuse")) {//internal storage
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
internalpath = internalpath.concat(columns[1] + "\n");
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Path of sd card external............"+externalpath);
System.out.println("Path of internal memory............"+internalpath);
}另一种选择:
此外,您还可以使用3d carousel来显示图像,并使用renderscrip作为替代方案。
http://code.google.com/p/android-ui-utils/downloads/detail?name=CarouselExample.zip。
生成的快照。在Jelly Bean上测试的Carousel 3d。

https://stackoverflow.com/questions/15390402
复制相似问题