我怎样才能显示在Android的Gallery3D(Cooliris的)一个特定的文件夹? [英] How can I display a specific folder in Android Gallery3D (cooliris)?

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

问题描述

我使用 Gallery3D(升级Froyo稳定)

我试图让一个小应用程序,在画廊视图显示特定文件夹中的映像。

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

推荐答案

错误查找专辑的问题很可能是由于这样的事实,你得到的DCIM文件夹中的 bucketId 从您的code没有任何图像直接在里面。你不应该得到错误例如,如果你使用/ DCIM /摄像机,而不是(假设有一些图像那里)。

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 code以补充修改,使其显示特定的文件夹时,如果你遵循这条路线(因为推出code只是没有设计使用这样的)。

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提供/图片 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天全站免登陆