@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { // 访问相册 if (requestCode == CommonConstant.REQUESTCODE_PHOTO_ALBUM) { String fileName = null; if (data != null) { // 得到图片的全路径 Uri uri = data.getData(); ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(uri, null, null, null, null); if (cursor.moveToFirst()) { do { fileName = cursor.getString(cursor.getColumnIndex("_data")); } while (cursor.moveToNext()); } tempFile = new File(fileName); if (tempFile.exists() && tempFile.length() > 0) { ImageItem albumPic = new ImageItem(); albumPic.setIsLocalPic(true); albumPic.setImagePath(fileName); picList.add(albumPic); editGridAdapter.notifyDataSetChanged(); } } } // 访问相机 if (requestCode == CommonConstant.REQUESTCODE_PHOTO_CAMERA) { if (FileUtils.hasSdcard()) { Bitmap bitmap = ImageUtils.scale(BitmapFactory.decodeFile(imagePath), 0.7F, 0.7F); if (null == imagePath || "".equals(imagePath)) { } else { tempFile = new File(imagePath); if (tempFile.exists() && tempFile.length() > 0) { // 判断照片是否被旋转,如果旋转则旋转回0° int degree = ImageUtils.getBitmapDegree(imagePath); if (degree != 0) { bitmap = ImageUtils.rotateBitmapByDegree(bitmap, degree); } ImageUtils.toFile(bitmap, tempFile); ImageItem takePhoto = new ImageItem(); takePhoto.setIsLocalPic(true); takePhoto.setImagePath(imagePath); picList.add(takePhoto); editGridAdapter.notifyDataSetChanged(); } else { } } } else { ToastUtils.showToast("未找到存储卡,无法存储照片!"); } } } super.onActivityResult(requestCode, resultCode, data); }
/** @Description: 初始化闲置物品信息 */ private void initSecondHandInfo() { titleET.setText(secondHandInfo.getTitle()); typeSp.setText(secondHandInfo.getType()); priceET.setText(secondHandInfo.getPrice()); describeET.setText(secondHandInfo.getDescribe()); picFileList = secondHandInfo.getPicFileList(); if (null == picFileList || 1 > picFileList.size()) { } else { for (BmobFile bmobFile : picFileList) { if (null != bmobFile) { ImageItem item = new ImageItem(); item.setIsLocalPic(false); item.setFileName(bmobFile.getFilename()); item.setImagePath(bmobFile.getFileUrl(AddSecondHandActivity.this)); picList.add(item); } } editGridAdapter.notifyDataSetChanged(); } if (secondHandInfo.getBargain()) { bargainSp.setText("可议价"); } else { bargainSp.setText("不可议价"); } qqET.setText(secondHandInfo.getQq()); phoneET.setText(secondHandInfo.getPhone()); }