2014-09-01 3 views
0

필자는 내 자신의 파일 탐색기를 코딩 했으므로 다양한 파일을 열 수있는 기능을 구현하기 시작하려고합니다. Mime Types와 다른 모든 것들을 구현했는데 특정 파일을 특정 "뷰어 활동"으로 어떻게 파싱 할 수 있습니까? 인 텐트를 사용하여 그 뷰어 앱에서 인 텐트를 받고 사용하는 방법을 알고 있습니다. 많은 분들께 감사드립니다 :)자신의 파일 탐색기에서 파일 열기

답변

0

이와 비슷한 것이 작동합니다. 파일을 원하는대로 변경하십시오.

File file = new File(Environment.getExternalStorageDirectory(), "movie.mp4"); 
int index = file.getName().lastIndexOf(".") + 1; 
String extension = null; 
if (index > 0) { 
    extension = file.getName().substring(index); 
} 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 
Uri u = Uri.parse("file://" + file.getAbsolutePath()); 
String mimeType = null; 
if (extension != null) { 
    mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 
} 
if (mimeType == null) { 
    mimeType = "*/*"; 
} 
intent.setDataAndType(u, mimeType); 
try { 
    startActivity(Intent.createChooser(intent, "Open with...")); 
} catch (ActivityNotFoundException e) { 
    // handle the exception 
} 
+0

죄송합니다. 나는 의도를 받아들이는 활동에서 그것을 다루는 방법을 물었다. – Trabefi

+0

아, 나는 그 질문을 오해했다. 이 같은 것이 작동해야합니다 : http://stackoverflow.com/questions/1733195/android-intent-filter-for-a-particular-file-extension –

관련 문제