【发布时间】:2015-07-17 22:50:54
【问题描述】:
您好,我们有文件选择器,当用户使用文件选择器选择文件时,希望返回所选文件的路径以供上传。现在我想如何获取所选文件的路径。我想要这样的文件路径--> /mnt/sdcard/DCIM/13.jpg
代码:
private void fnFileChooser(){
Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try{
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
fileSelectedCode);
}
catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
path=uri.getPath();
txtAddress.setText(uri.getPath());
ImageView img=(ImageView) findViewById(R.id.imgTest);
img.setImageURI(uri);
/*String path = FileUtils.getPath(this, uri);
Log.d(TAG, "File Path: " + path);*/
// Get the file instance
// File file = new File(path);
// Initiate the upload
}
super.onActivityResult(requestCode, resultCode, data);
}
【问题讨论】:
-
we have file picker。请详细说明。你自己做的?你用的是哪一个? -
我认为他指的是Microsoft OneDriveSDK,它有一个名为picker的包。