如何在 Android Gallery3D (cooliris) 中显示特定文件夹? [英] How can I display a specific folder in Android Gallery3D (cooliris)?

查看:27
本文介绍了如何在 Android Gallery3D (cooliris) 中显示特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Gallery3D(froyo-stable)

我正在尝试制作一个小应用程序,该应用程序仅在图库视图中显示特定文件夹中的图像.

I'm trying to make a little app that displays only images from a specific folder in a gallery view.

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);

我该如何解决这个问题?谢谢你

How can I fix this? Thankyou

推荐答案

错误查找专辑"问题很可能是由于您从中获取 bucketId 的DCIM"文件夹造成的在您的代码中没有直接包含任何图像.例如,如果您使用/DCIM/Camera"代替(假设那里有一些图像),则不会出现错误.

The "Error finding album" issue is most likely due to the fact that the "DCIM" folder that you get the bucketId from in your code does not have any images directly in it. You should not get the error if for example you use "/DCIM/Camera" instead (assuming there are some images there).

但是,如果我正确理解您想要什么,我相信您需要对 Gallery3D 代码进行额外的修改,以使其在启动时显示特定文件夹,如果您遵循此路线(因为代码只是不是为了那样使用而设计的).

However, if I understand correctly what you want, I believe there are additional modifications that you need to make on the Gallery3D code in order to make it display a specific folder when launched if you follow this route (since the code is just not designed to be used like that).

我相信您可以通过在 onCreate() 中将意图设置为特定的意图来更轻松地实现您想要的目标,而不是使用上面的代码:

Instead of using your code above, I believe you can achieve what you want more easily by setting the intent to a specific one in 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);
}

基本上,我们在这里所做的是利用应用的 ACTION_VIEW 意图处理,当它提供 vnd.android.cursor.dir/image MIME 类型时.

Basically what we are doing here is leveraging the ACTION_VIEW intent handling of the app when it is supplied with a vnd.android.cursor.dir/image MIME type.

这篇关于如何在 Android Gallery3D (cooliris) 中显示特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆