如何在android活动中以编程方式仅打开文件管理器文件夹中的图像

如何在android活动中以编程方式仅打开文件管理器文件夹中的图像,android,android-intent,android-activity,android-afilechooser,Android,Android Intent,Android Activity,Android Afilechooser,我正在开发一个android gallery应用程序,所以我只想在单击文件选择器按钮时打开图像/照片文件夹 我正在尝试打开它,但所有不必要的文件夹都显示打开的活动music/video/contact/。等等。我只想打开 显示图像和文件文件夹 这是我的文件选择器代码。我正在使用ACTION_PICK进行开放式活动 public void showFileChooser(View v) { Intent intent = new Intent(Intent.ACTION

我正在开发一个android gallery应用程序,所以我只想在单击文件选择器按钮时打开图像/照片文件夹

我正在尝试打开它,但所有不必要的文件夹都显示打开的活动music/video/contact/。等等。我只想打开 显示图像和文件文件夹

这是我的文件选择器代码。我正在使用ACTION_PICK进行开放式活动

 public void showFileChooser(View v) {

            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("/*");

            if(Build.VERSION.SDK_INT >= 15 && Build.VERSION.SDK_INT <= 18){
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                intent.setAction(Intent.ACTION_GET_CONTENT);

                try {
                    startActivityForResult(
                            Intent.createChooser(intent, "Select Picture"),FILE_SELECT_CODE);
                } catch (ActivityNotFoundException ex) {
                    // Potentially direct the user to the Market with a Dialog
                    Toast.makeText(this, "Please install a File Manager.",
                            Toast.LENGTH_SHORT).show();
                }

            }

           else if(Build.VERSION.SDK_INT >= 19){
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                intent.setAction(Intent.ACTION_PICK);

                try {
                    startActivityForResult(
                            Intent.createChooser(intent, "Select Picture"),FILE_SELECT_CODE);
                } catch (ActivityNotFoundException ex) {
                    // Potentially direct the user to the Market with a Dialog
                    Toast.makeText(this, "Please install a File Manager.",
                            Toast.LENGTH_SHORT).show();
                }
            }

           else {
               Log.e("no","no");
            }

}
谢谢。

试试这个:

if (Build.VERSION.SDK_INT >= 23) {
                    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
                    } else {
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction("android.intent.action.PICK");
                        startActivityForResult(Intent.createChooser(intent, "Select picture using"), 101);
                    }
                } else {
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction("android.intent.action.PICK");
                    startActivityForResult(Intent.createChooser(intent, "Select picture using"), 101);
                }
如果你想要一个文件夹列表,那么你可以使用这个库


嗨@sagar谢谢你的回答,但这并不是我所期望的。。。我只想显示图像文件夹和文件文件夹,如果您想查看存储中的所有图像文件夹,则需要在应用程序中创建自定义图库