龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

android調(diào)用相冊或攝像頭拍照回調(diào)路徑

2015.09.10 | 739閱讀 | 0條評論 | 未命名

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { ContentResolver resolver = getContentResolver(); 相冊中獲取的uri正常 if (requestCode == 0) { try { Uri uri = data.getData(); Log.v("uri_xiangce",""+uri); Cursor cursor = resolver.query(uri, null, null, null, null); cursor.moveToFirst(); String imgNo = cursor.getString(0); //圖片編號 imgPath = cursor.getString(1); //圖片文件路徑 Log.v("imagpath", ""+imgPath); String imgSize = cursor.getString(2); //圖片大小 Log.v("imgSize", ""+imgSize); String imgName = cursor.getString(3); //圖片文件名 Log.v("imgName", ""+imgName); try { InputStream in = resolver.openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(in); ivPortrait.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } 但是相機(jī)中的uri就是一個null else if(requestCode ==1){ try { super.onActivityResult(requestCode, resultCode, data); Uri uri = data.getData(); Log.v("uri_xiangji", ""+uri); Bundle extras = data.getExtras(); myBitmap = (Bitmap) extras.get("data"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); myBitmap.compress(Bitmap.CompressFormat.JPEG , 100, baos); mContent=baos.toByteArray(); Cursor cursor = resolver.query(uri, null, null, null, null); cursor.moveToFirst(); String imgNo = cursor.getString(0); //圖片編號 imgPath = cursor.getString(1); //圖片文件路徑 Log.v("imagpath", ""+imgPath); String imgSize = cursor.getString(2); //圖片大小 Log.v("imgSize", ""+imgSize); String imgName = cursor.getString(3); //圖片文件名 Log.v("imgName", ""+imgName); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //把得到的圖片綁定在控件上顯示 ivPortrait.setImageBitmap(myBitmap); } }

贊 (

發(fā)表評論