与文件夹过滤图库 [英] Gallery with folder filter

查看:94
本文介绍了与文件夹过滤图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code开一个画廊我的应用程序里面

I'm using following code to open a gallery inside of my app

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, FIND_RESULT);

是否有可能限制图像来采取相机只显示图像的名单?在我的2.1系统查看照片,图像分组,以便必须有一个定义,以哪个文件夹所属。

Is it possible to limit a list of images to only show images taken by camera? Viewing Gallery on my 2.1 system, images are grouped so there has to be a parameter that defines to which folder it belongs.

检查<一href="http://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns.html">MediaStore.Images.ImageColumns我没有一个发现将定义这种事情任何列。

Checking the MediaStore.Images.ImageColumns I did not a find any column that would define such thing.

我可能是错的?因为如果我能创建一个查询,按文件夹进行筛选,并创建我自己的画廊看法,那么我的问题就迎刃而解了。

Could I be wrong? Because if I could create a query to filter by folder and create my own gallery view, then my problem would be solved.

推荐答案

您只需要在你的活动来实现MediaScannerConnectionClient,之后你必须给该文件夹的名称里面的文件之一的确切路径这里SCAN_PATH它将扫描所有包含该文件夹中的文件并打开它内建的画廊。所以,只要给的名字,你的文件夹,你会得到里面包括视频中的所有文件。如果你想打开的映像更改 FILE_TYPE =图像/ *

You just need to implement MediaScannerConnectionClient in your activity and after that you have to give the exact path of one of the file inside that folder name here as SCAN_PATH and it will scan all the files containing in that folder and open it inside built in gallery. So just give the name of you folder and you will get all the files inside including video. If you want to open only images change FILE_TYPE="image/*"

public class SlideShow extends Activity implements MediaScannerConnectionClient {

        public String[] allFiles;
        private String SCAN_PATH ;
        private static final String FILE_TYPE = "*/*";
        private MediaScannerConnection conn;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            File folder = new File("/sdcard/yourfoldername/");
            allFiles = folder.list();

            SCAN_PATH=Environment.getExternalStorageDirectory().toString()+"/yourfoldername/"+allFiles[0];

            Button scanBtn = (Button) findViewById(R.id.scanBtn);
            scanBtn.setOnClickListener(new OnClickListener()
            {
                public void onClick(View v)
                {
                    startScan();
                }
            });
        }

        private void startScan()
        {
            if(conn!=null)
            {
                conn.disconnect();
            }

            conn = new MediaScannerConnection(this, this);
            conn.connect();
        }


        public void onMediaScannerConnected()
        {
            conn.scanFile(SCAN_PATH, FILE_TYPE);    
        }


        public void onScanCompleted(String path, Uri uri)
        {
            try
            {
                if (uri != null) 
                {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(uri);
                    startActivity(intent);
                }
            }
            finally 
            {
                conn.disconnect();
                conn = null;
            }
        }
    }

这篇关于与文件夹过滤图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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