簡體   English   中英

以圖庫意圖顯示圖像

[英]Displaying an image in gallery intent

有什么方法可以創建一個可以打開該畫廊並在其中顯示特定圖像的意圖嗎? 我並不是在問如何將圖像保存到內存中,而只是想以一種可以縮放的方式來顯示圖像(不在ImageView中)的正確而簡便的方法。

您可以使用IntentACTION_VIEW來實現:

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.parse("file://" + "YOUR_FILE's PATH");
//Or you can use                 
Uri uri = Uri.fromFile(new File("YOUR_FILE's PATH"));
intent.setDataAndType(uri,"image/*");
startActivity(intent);

如果您要定位或設備的API級別為24+,請參考此答案以查看如何獲取正確的Intent並避免FileUriExposedException

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM