我正在创建一个图像转换器应用程序,需要用户从设备中选择图像文件,我使用模拟器,当我开始打算从图库中选择一个文件时,它会在他们的文件夹中显示图像,但是在单击文件夹时,它只是重新打开画廊而不是文件夹这是我的代码
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, getString(R.string.selectf)),
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();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
//Log.d(TAG, "File Uri: " + uri.toString());
// Get the path
try {
Path = getPath(this, uri);
if( Path.endsWith("png") || Path.endsWith("gif") || Path.endsWith("jpg") || Path.endsWith("bmp")){
startprogress2();
progressDialog.onStart();
asyncTask = new loadAction();
asyncTask.execute();
}
else{
Toast.makeText(this, R.string.selecti,
Toast.LENGTH_SHORT).show();
}
}catch (URISyntaxException e) {
e.printStackTrace();
failtoloadtoast();
}catch(Exception e){
e.printStackTrace();
failtoloadtoast();
}
}else{
failtoloadtoast();
}
super.onActivityResult(requestCode, resultCode, data);
}
请记住,我必须使用户能够从文件管理器中选择图像文件,不仅是画廊,因为画廊不读取某些格式。