@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
importFile = new File(uri.getPath());
String sFilePath = importFile.getAbsolutePath();
if (uri.getPath() != null) {
edImportPath.setText(uri.getPath());
}
Log.d("File uri", "File Uri: " + uri.toString());
// Get the path
try {
String path = getPath(this, uri);
Log.d("File Path", "File Path: " + path);
// Get the file instance
// File file = new File(path);
// Initiate the upload
} catch (URISyntaxException use) {
use.printStackTrace();
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
public static String getPath(Context context, Uri uri) throws URISyntaxException {
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = { "_data" };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
// Eat it
}
}
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
uri.getPath() = /document/primary:SiHAS/CfgFile/SiHAS_Setting_SHINA_LAB.txt
uri.toString() = content://com.android.externalstorage.documents/document/primary%3ASiHAS%2FCfgFile%2FSiHAS_Setting_SHINA_LAB.txt
getPath(this, uri) = null
절대경로값이 아니게 나오는데
절대경로를 어떻게 하면 얻을 수 있을까요?