簡體   English   中英

如何通過共享選項將我從圖庫中選擇的圖像設置到imageview中的應用程序中。

[英]How can i set my selected image from gallery to my application in imageview via share option.

我正在構建一個應用程序,在其中可以將圖庫中的照片共享到應用程序中,與“ PINTEREST”的概念相同。 但是它通過登錄網關進行訪問,如果用戶已經登錄,則它將選擇的圖像設置為imageview,或者將其中一個登錄設置為繼續。 共享選項直接來自電話圖庫的共享菜單,就像我們單擊圖庫中的共享選項(如郵件,藍牙等)時在列表視圖中看到的那樣。

我想知道,如何通過圖庫中的共享選項登錄后將所選圖像設置為應用程序的圖像視圖。

我得到了我的答案:)這可以通過使用Intent來完成:

Intent intent = getIntent();
// Get the action of the intent
String action = intent.getAction();
// Get the type of intent (Text or Image)
String type = intent.getType();
// When Intent's action is 'ACTION+SEND' and Tyoe is not null
if (Intent.ACTION_SEND.equals(action) && type != null) {
     if (type.startsWith("image/")) { // When type is 'image/*'
           handleSendImage(intent); // Handle single image being sent
       }
}
private void handleSendImage(Intent intent) {
    // Get the image URI from intent
    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    // When image URI is not null
    if (imageUri != null) {
        // Update UI to reflect image being shared
        view_news.setImageURI(imageUri);
        news.setVisibility(View.GONE);
    } else{
        Toast.makeText(this, "Error occured, URI is invalid", Toast.LENGTH_LONG).show();
    }
}

這解決了我從圖庫獲取圖像並將其顯示在imageview中的問題,就像在“ pInterest”應用程序中一樣。 謝謝 :)

暫無
暫無

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

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