欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 打開相冊選擇單張圖片實現(xiàn)代碼

 更新時間:2017年05月10日 14:59:24   作者:Mars-xq  
這篇文章主要介紹了Android 打開相冊選擇單張圖片實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下

Android 打開相冊選擇單張圖片實現(xiàn)代碼

                以下就是如何在應(yīng)用中打開圖庫并選擇一張圖片進行應(yīng)用,代碼很簡單,注釋很詳細。

實現(xiàn)代碼:

btn8.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
/*在Activity Action里面有一個“ACTION_GET_CONTENT”字符串常量,
// 該常量讓用戶選擇特定類型的數(shù)據(jù),并返回該數(shù)據(jù)的URI.我們利用該常量,
//然后設(shè)置類型為“image/*”,就可獲得Android手機內(nèi)的所有image。*/
        Intent intent = new Intent();
        /* 開啟Pictures畫面Type設(shè)定為image */
        intent.setType("image/*");
        /* 使用Intent.ACTION_GET_CONTENT這個Action */
        intent.setAction(Intent.ACTION_GET_CONTENT);
        /* 取得相片后返回本畫面 */
        startActivityForResult(intent, 1);


//Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// startActivityForResult(intent, RESULT);
      }
    });



 @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
      Uri uri = data.getData();
      Log.e("uri", uri.toString());
      ContentResolver cr = this.getContentResolver();
      try {
        Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
        /* 將Bitmap設(shè)定到ImageView */
        iv8.setImageBitmap(bitmap);
      } catch (FileNotFoundException e) {
        Log.e("Exception", e.getMessage(), e);
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論