2016-10-28 7 views
0

Open With 대화 상자에서 내 앱을 선택했을 때 URI을 방금 가져온 것 같습니다. screenshot. 하지만 난 항상 intent.getParcelableExtra(Intent.EXTRA_STREAM) 제공된 코드 샘플에서 null이됩니다.캡처 한 스크린 샷의 URI를 intent.getParcelableExtra (Intent.EXTRA_STREAM)에서 가져올 수 없습니다!

이것은 내 intent filter :

구현이 intent-filter

먼저 하나를 내 활동이 주 ​​및 실행 만듭니다.

두 번째는 :. (이미지 뷰어로 등록 시스템이 활동을)

<intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <data android:mimeType="image/*" /> 
</intent-filter> 

그것은 이미지 뷰어 만듭니다 그리고 이것은 내가 호출 의도에서 URI을 얻으려고 어떻게 내 활동. the documentation for ACTION_VIEW을 인용

Intent intent = getIntent(); 
String action = intent.getAction(); 
String type = intent.getType(); 

if (Intent.ACTION_VIEW.equals(action) && type != null) { 
    if (type.startsWith("image/")) { 
     Uri mediaUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); 
     // Here mediaUri is always null 
    } 
} 
+1

열린 우리당 값 데이터 필드에있을 것입니다, 당신은 intent.getData를 사용해야합니다(). – Baba

답변

1

:

입력 : GetData의()는 데이터를 검색 할 URI이다. 에

그래서, 코드를 변경 :

Intent intent = getIntent(); 
String action = intent.getAction(); 
String type = intent.getType(); 

if (Intent.ACTION_VIEW.equals(action) && type != null) { 
    if (type.startsWith("image/")) { 
     Uri mediaUri = intent.getData(); 
    } 
} 
1
Intent intent = getIntent(); 
String action = intent.getAction(); 
String type = intent.getType(); 

if (Intent.ACTION_VIEW.equals(action) && type != null) { 
    if (type.startsWith("image/")) { 
     Uri mediaUri = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); 
     // Here mediaUri is always null 
    } 
} 
+0

컴파일러는 "'intent.getParcelableExtra (Intent.EXTRA_STREAM)'을'URI'가'중복 '이라고합니다. 그리고 운이 좋으면 전에도 해봤습니다. – Eftekhari