与文件夹过滤图库文件夹、图库

由网友(何以笙萧默)分享简介:我用下面的code开一个画廊我的应用程序里面I'm using following code to open a gallery inside of my appIntent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("image/...

我用下面的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.

检查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;
            }
        }
    }
阅读全文

相关推荐

最新文章