2016-10-28 7 views
0

私はOpen Withダイアログから自分のアプリを選んだので、ちょうどscreenshotをキャプチャしたURIを取得しようとしています。しかし、私は常に提供されたコードサンプルでintent.getParcelableExtra(Intent.EXTRA_STREAM)からヌルを取得します。キャプチャされたスクリーンショットのURIをintent.getParcelableExtra(Intent.EXTRA_STREAM)から取得できません!

これは私のintent filter

実装2 intent-filter

第1:私の活動がメインとランチャします。

第二1:

<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

関連する問題