我試圖從Open With
對話框中選取剛截取的screenshot
的URI
。但是在提供的代碼示例中,我總是從intent.getParcelableExtra(Intent.EXTRA_STREAM)
中得到空值。無法從intent.getParcelableExtra(Intent.EXTRA_STREAM)獲取捕獲的屏幕截圖的URI!
這是我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
我。活動。
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
}
}
URI值將在數據領域,你需要使用intent.getData()。 – Baba