2012-03-29 4 views
15
을 입력하십시오.

인 텐트를 사용하여 사용자가 파일을 선택할 응용 프로그램을 선택하는 "작업 완료"를 선택하는 방법 (장치에서 파일을 탐색 할 응용 프로그램이 몇 개인 경우)파일 브라우저를 선택하기 위해 파일 브라우저를 선택하는 방법 intent를 사용하여

나는 연장 .. 사용하여 파일을 필터링 할 (예를 :. * .sav, * .props)

가 사전에 감사

이 같은 것을 사용할 수 있습니다
+0

방문이 스레드에 따라 조치를 변경할 수 있습니다, http://stackoverflow.com/questions/5537907/view -file-path-in-a-file-manager-as-android-intent 내가 잘못하지 않았다면, 도움이 될 것입니다. –

답변

39

:

.... 
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("file/*"); 
    startActivityForResult(intent, YOUR_RESULT_CODE); 
    .... 

B 유감스럽게도 필터 타사 파일 브라우저를 설정할 수 있는지 의심 스럽습니다. 또는이 파일 대화 상자를 사용해 볼 수 있습니다. http://code.google.com/p/android-file-dialog/

+2

링크를 주셔서 감사합니다 :) 정말 간단하고 유용한 파일 브라우저 –

+6

대신 intent.setType ("*/*")'을 사용해야했습니다. 내가 아는 MIME 유형은'file /'로 시작하지 않습니다. – Alicia

-5

// 여기 KITKAT 또는 새 버전을 확인하면 samsung 파일 탐색 문제도 해결됩니다.

boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 
if (isKitKat) { 
    Intent intent = new Intent(); 
    intent.setType("*/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(intent,FILE_SELECT_CODE); 
} else { 
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("*/*"); 
    startActivityForResult(intent,FILE_SELECT_CODE); 
} 
+9

if/else의 코드는 동일하게 동작합니다. – roplacebo

6

사용 가능한 경우 빌드 파일 탐색기가 열리 며, 그렇지 않으면 u가 설치 한 파일 탐색기를 선택하라는 메시지가 표시됩니다.

private void showFileChooser() { 

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    //intent.setType("*/*");  //all files 
    intent.setType("text/xml"); //XML file only 
    intent.addCategory(Intent.CATEGORY_OPENABLE); 

    try { 
     startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE); 
    } catch (android.content.ActivityNotFoundException ex) { 
     // Potentially direct the user to the Market with a Dialog 
     Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); 
    } 
} 
0

그것은 문서 파일을 선택하는 데 도움이 될 수 있으며, u는 당신의 필요

 Intent intent; 
     if (VERSION.SDK_INT >= 19) { 
      intent = new Intent("android.intent.action.OPEN_DOCUMENT"); 
      intent.setType("*/*"); 
     } else { 
      PackageManager packageManager =getActivity().getPackageManager(); 
      intent = new Intent("android.intent.action.GET_CONTENT"); 
      intent.setType("file*//*"); 
      if (packageManager.queryIntentActivities(intent,MEDIA_TYPE_IMAGE).size() == 0) { 
       UserToast.show(getActivity(), getResources().getString(R.string.no_file_manager_present)); 
      } 
     } 
     if (getActivity().getPackageManager().resolveActivity(intent, NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST) != null) { 
      startActivityForResult(intent, UPLOAD_FILE); 
     } 
관련 문제