我是android开发的新手,我打算在本地选择文件,以便将其上传到一些云存储中。我已经意识到很多情况,返回的文件名以image:b
的形式表示某个数字b
。例如,对于文件,我得到path = /document/image:91
和filename = image:91
。这是否意味着我的结果是错误的?我期望得到实际的文件名。我只想知道我的代码是否正确。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "requestCode: " + requestCode);
Log.d(TAG, "resultCode: " + resultCode);
Log.d(TAG, "Actiity.RESULT_OK: " + Activity.RESULT_OK);
Log.d(TAG, "intent data: " + data);
if (requestCode == CHOOSE_FILE_REQUESTCODE && resultCode == Activity.RESULT_OK && null != data) {
Uri image = data.getData();
String path = image.getPath();
this.file = new File(path);
String filename = image.getLastPathSegment();
//File destination = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/CustomFolder/" + filename);
Log.d(TAG, "file name: " + filename);
Log.d(TAG, "file path: " + path);
this.fileName.setText(filename);
}
}
开始意图。
public void onClickSelectPhoto(View v){
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
}