我已使用Intent.ACTION_GET_CONTENT
选择了该文件当我打印路径时,它不会显示确切的路径。
代码:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
startActivityForResult(intent, PICKFILE_RESULT_CODE);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICKFILE_RESULT_CODE:
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
String filePath = uri.getPath();
Toast.makeText(getActivity().getApplicationContext(),
filePath, Toast.LENGTH_SHORT).show();
}
}
}
输出:/document/primary:Documents/Test.txt
预期输出:sdcard/Documents/Test.txt