首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在安卓Gallery3D (cooliris)中显示特定的文件夹?

如何在安卓Gallery3D (cooliris)中显示特定的文件夹?
EN

Stack Overflow用户
提问于 2013-03-14 00:02:52
回答 2查看 3K关注 0票数 4

我正在使用Gallery3D (froyo-stable)

我正在尝试做一个小应用程序,它只显示画廊视图中特定文件夹中的图像。

代码语言:javascript
复制
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()

代码语言:javascript
复制
// Creating the DataSource objects.
final LocalDataSource localDataSource = new LocalDataSource(Gallery.this, targetUri.toString(), false);

但我错了

代码语言:javascript
复制
"Error finding album " + bucketId);

CacheService.loadMediaSets.

代码语言:javascript
复制
 Log.e(TAG, "Error finding album " + bucketId);

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-24 14:51:08

“错误查找相册”的问题很可能是因为在代码中获取bucketId的"DCIM“文件夹中没有直接包含任何图像。例如,如果你使用"/DCIM/Camera“代替(假设有一些图像),你应该不会得到错误。

但是,如果我正确理解了您想要什么,我相信您需要对Gallery3D代码进行额外的修改,以使它在启动时显示一个特定的文件夹(因为代码不是被设计成这样使用的)。

与使用上面的代码相比,我相信通过将意图设置为onCreate()中的特定意图,您可以更容易地实现您想要的内容

代码语言:javascript
复制
@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意图处理。

票数 1
EN

Stack Overflow用户

发布于 2013-03-24 17:55:37

假设您需要查找某个文件夹下的文件路径。

代码语言:javascript
复制
    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。所以为了确保你得到正确的路径,你可以使用下面的代码。

代码语言:javascript
复制
 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。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15390402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档