[問題] 相簿取圖和連結至imageview

看板AndroidDev作者 (反吱野心家)時間13年前 (2013/01/03 23:57), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
節錄部分程式碼 buttonPhoto.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent intentPhoto = new Intent(); intentPhoto.setType("image/*"); intentPhoto.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intentPhoto, 1); } }); 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 bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); // 將Bitmap設定到ImageView image.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(),e); } } super.onActivityResult(requestCode, resultCode, data); } 參考網路作的 正常按鈕點擊時可以進入相簿選擇畫面 但是實機跑的時候點擊相簿相片後卻無法順利取圖 即完成時並沒有進入onActiVityResult函式 希望板上的高人指導我遺忘了哪些東西 我菜鳥設計師的案子很急的感激不盡 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.63.37

01/05 22:04, , 1F
會不會只是result code不符預期?
01/05 22:04, 1F
文章代碼(AID): #1GvQftTx (AndroidDev)