2017-12-26 15 views
1

나는 하나의 활동에서 다른 활동으로 URI를 단순히 전달하려고합니다. 그리고 그 일을하는 동안 나는 아무 파일도 발견되지 않았다는 것을 알아 차렸고 나는 그것들을 인쇄함으로써 최종 파일 이름이 같지 않다는 것을 알 수있었습니다. (그냥 path 문자열과 uri.getEncodedPath()) Android : Uri 파일 이름 혼동

그래서 내가 문자열을 보내고 다음과 같이 URI를 재구성 시도 :

Log.e("debug_path_string", data.getExtras().getString(CONSTANT)); 

# try { Uri photoUri = Uri.fromFile(new File(data.getExtras().getString(CONSTANT))); } 
try { Uri photoUri = Uri.parse(data.getExtras().getString(CONSTANT)); } 
catch (Exception e) { Log.e("IO", e.getMessage()); } 

Log.d("debug", photoUri.getEncodedPath()); 
pageListAdapter.append(photoUri); 

및 로그

12-26 04:18:04.172 4425-4425/com.example.myawesomeapp E/debug_path_string: /storage/emulated/0/Android/data/com.example.myawesomeapp/files/Pictures/JPEG_20171226_041803672615875.jpg 
12-26 04:18:04.172 4425-4425/com.example.myawesomeapp D/debug: /document_images/JPEG_20171226_041746-1723016833.jpg 
12-26 04:18:04.225 4425-4425/com.example.myawesomeapp W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored 
12-26 04:18:04.400 4425-4425/com.example.myawesomeapp W/Glide: Load failed for content://com.example.myawesomeapp.fileprovider/document_images/JPEG_20171226_041746-1723016833.jpg 

있습니까

file://storage/emulated/0/Android/data/com.example.myawesomeapp/files/Pictures/JPEG_20171226_041803672615875.jpg 
content://com.example.myawesomeapp.fileprovider/document_images/JPEG_20171226_041746-1723016833.jpg 

# provided 
# com.example.myawesomeapp.fileprovider/document_images resolves path 
# storage/emulated/0/Android/data/com.example.myawesomeapp/files/Pictures 

동등한?

분명히 이러한 파일을 찾을 수 없어로드에 실패했습니다. (문자열 경로에 파일 이름이있는 경로와 파일을 확인했습니다).

누군가 Uri.parse() 또는 Uri.fromFile(new file(path))이 원본과 다른 파일 이름을 생성하려고하는 이유를 설명 할 수 있습니까?

왜 안드로이드는 JPEG_20171226_041803672615875을 싫어하지만 JPEG_20171226_041746-1723016833을 싫어하는 것일까 요?


참고 : 내가 직접 data.putExtra()data.getParcelableExtra()를 사용하여 Uri를 전송하려고했다. 그들은 내가 그 끈을 보내고 그것으로부터 Uri을 만들었던 것과 같은 결과를주고 있습니다.


업데이트 : 마지막에 임의의 숫자를 추가 File.createTempFile()을 사용하고. 그것도 FilesProvider는 자신의 참조를 생성하고있다, 그는 원래 파일 이름을 만지지 말았어야 JPG_date_time입니다.

변경된 사항을 관찰하면서 방금이 이상한 점을 발견했습니다.

|......16.......||.......rest......| 

JPEG_20171226_041803672615875.jpg 
JPEG_20171226_041746-1723016833.jpg 

# Running one more example 
JPEG_20171226_121309-2003514507.jpg 
JPEG_20171226_121239-882490989.jpg 

|......16.......||.......rest......| 

처음 16자를 보존하고 있습니다 ... !!! 이것은 내가 길이와 관련이 있다는 것을 분명히 느끼게합니다. 다른 활동에 열린 양식을 하나의 활동을 전달하려는 경우

+0

https://developer.android.com/training/secure-file-sharing/setup-sharing.html –

+0

photoUri.toString()을 살펴보십시오. – greenapps

+0

나는이 16 글자가 워드 프로세서로도 경고로 언급되지 않은 이유에 놀랐다. –

답변

0

그것은 이상하게 문제를 일으키는 길이였다.

파일 이름을 16 자 미만으로 유지하면 문제가 해결됩니다. 예, 변경하지 않고도 그렇게 작동합니다. 알림 File.createTempFile()을 사용하는 경우 (여기서는 9였습니다)과 같은 문자가 5 자 이상 추가됩니다 (here).

지금까지 문제가 해결되었지만 다른 질문이 있습니다. 16 자 이상을 원하면 어떻게해야합니까?

-3

때문에,이 같은 의도를 사용하십시오 :

Uri Uri1=new Uri(); 
class A: 
Intent intent=new Intent(A.this,B.class) 
intent.set Data(Uri1); 
start Activity(intent); 
Class B 
Intent intent=getIntent(); 
Uri uri=intent.getData();