2012-08-13 3 views
7

웹 및 스택 오버 플로우에는 ACTION_GET_CONTENT 인 텐트를 사용하여 다른 Android 앱에서 파일을 가져 오는 방법 (예 : 전자 메일 첨부 파일로 사용)에 대한 몇 가지 예가 포함되어 있습니다. 그러나 ACTION_GET_CONTENT 이벤트 (예 : 전자 메일 첨부 선택)와 같이이 앱을 선택할 수있는 콘텐츠를 제공하는 애플리케이션을 만들기 위해 어떤 클래스를 구현해야합니까?Intent.ACTION_GET_CONTENT에 대한 콘텐츠 제공 방법

ContentProvider가 올바른 솔루션입니까? AndroidManifest.xml에 무엇을 추가해야합니까?

답변

15

웹 검색 몇 시간이 지난 후 다음 해결책을 찾았습니다.

  1. 활동 처리 의도를 구현합니다. 매니페스트에 다음을 추가

    Uri resultUri = // the thing to return 
    Intent result = new Intent(); 
    result.setData(resultUri); 
    setResult(Activity.RESULT_OK, result); 
    finish(); 
    
  2. : 내 다음 이상의 특정 코드를 사용

    <activity 
        android:name="ActivityName" 
        android:label="Some label" > 
        <intent-filter> 
         <action android:name="android.intent.action.GET_CONTENT" /> 
         <category android:name="android.intent.category.OPENABLE" /> 
         <category android:name="android.intent.category.DEFAULT" /> 
         <data android:mimeType="*/*" /> 
        </intent-filter> 
        <intent-filter> 
         <action android:name="android.intent.action.PICK" /> 
         <category android:name="android.intent.category.DEFAULT" /> 
         <data android:mimeType="*/*" /> 
        </intent-filter> 
    </activity> 
    
+0

는이 경우 http://stackoverflow.com/questions/14151970/extra-slash-appends-with-file-uri에서 작동하지 복용량 참조하십시오 -so-file-name-is-set-empty-in-file-input-contr –

+0

ACTION_PICK 인 텐트 필터없이 저에게 적합합니다. 의도 필터가 응답해야하는 경우에 대한 아이디어는 무엇입니까? 사전/사후 KK 모두에서 GET_CONTENT 의도로 작업하는 것 같습니다. – cargo8

0

도 EXTRA_ALLOW_MULTIPLE true로 설정 한 수 API 레벨 18 수신 의도에서 시작 이 경우 하나 이상의 파일을 결과로 다시 보낼 수 있습니다. 이렇게하려면 당신은 ClipData로 설정해야합니다

resultIntent.setClipData(clipData) 
관련 문제