파일을 서버에 업로드하고 싶습니다. 그래서 파일 선택기를 사용합니다. 하지만 몇 가지 응용 프로그램에 문제가있어 uri에서 실제 경로를 얻을 수 있습니다. 대/소문자가 콘텐츠 인 경우 ideo, 오디오 또는 이미지 또는 직접 경로를 얻을 수 있다면 문제가 없습니다. 방법은 다음과 같습니다 :Uri에서 실제 경로를 얻는 방법?
public String getRealAudioPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Audio.Media.DATA };
//This method was deprecated in API level 11
//Cursor cursor = managedQuery(contentUri, proj, null, null, null);
CursorLoader cursorLoader = new CursorLoader(
this,
contentUri, proj, null, null, null);
Cursor cursor = cursorLoader.loadInBackground();
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
이미지 및 비디오 용입니다. 하지만 내 문제는 내용이 말해도에있을 때이다 :
content://com.dataviz.dxtg.documentprovider/document/file%3A%2F%2F%2Fmnt%2Fsdcard%2FDownload%2Arbres.png
나는 방법
private String getFilePathFromContentUri(Uri selectedVideoUri,
ContentResolver contentResolver) {
String filePath;
String[] filePathColumn = {MediaStore.MediaColumns.DATA};
Cursor cursor = contentResolver.query(selectedVideoUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
filePath = cursor.getString(columnIndex);
cursor.close();
return filePath;
}
을 시도 그래서 열린 우리당에서 실제 경로를 얻을하려면 어떻게 다른 콘텐츠 형식이있는 경우.
내 실제 경로는 아래와 같습니다 얻을 :
//Uri return from external activity
orgUri = data.getData();
text1.setText("fichier à envoyer " + orgUri.toString() + "\n");
// imagepath = orgUri.toString() ;
//path converted from Uri
//convertedPath = orgUri.getPath();
if(orgUri.toString().contains(IMAGEMEDIA)){
convertedPath = getRealPathFromURI(orgUri);
} else if(orgUri.toString().contains(AUDIOMEDIA)){
convertedPath = getRealAudioPathFromURI(orgUri);
}
else if(orgUri.toString().contains(VIDEOMEDIA)){
convertedPath = getRealvideoPathFromURI(orgUri);
}else {
if(orgUri.toString().contains("content")){
convertedPath = getFilePathFromContentUri(orgUri,
getApplicationContext().getContentResolver());
} else {
convertedPath = orgUri.getPath();
}
}
이없는 그들 모두에 대한 몇 가지 프로그램 자체에 대한 작동합니다. 나는 코드로가는 길을 추가했다. 나를 위해 모든 작동 – zied
는 –
당신은 당신이 결과 나는 결과 을위한 활동을 시작하는 방법에 대해 얘기 오전 filechooser – zied