Android调用摄像头拍照

添加权限:

<!-- 摄像头权限 -->
    <uses-permission android:name="android.permission.CAMERA"/>
    <!-- SD卡读写权限 -->
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

关键代码:

/**  
	 * @ClassName: addPictureListenerImpl  
	 * @Description: 添加图片
	 * @author chenzheng
	 * @date 2014-5-6 下午2:51:46  
	 */
	private class addPictureListenerImpl implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
			startActivityForResult(intent,1);
		}
		
	}
	
	protected void onActivityResult(int requestCode, int resultCode,
			Intent data) {
		if (requestCode == 1) {
			if (resultCode == RESULT_OK) {
				Bundle bm = data.getExtras();
				Bitmap bitmap = (Bitmap) bm.get("data");
				pic1.setImageBitmap(bitmap);
			}
		}
	}

相关推荐