我正在开发一个 android 图库应用程序,所以当我单击文件选择器按钮时,我只想打开图像/照片文件夹,
我正在尝试打开它,但所有不必要的文件夹都显示打开的活动(音乐/视频/联系人/.etc)。我只想打开该图像和文件文件夹。
这是我的文件选择器代码。我正在使用 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");
}
}
谢谢你。