Chụp ảnh hay lấy ảnh trong máy sử dụng các thành phần có sẵn trên máy --> sử dụng Intent 1. Chụp ảnh Trong manifest file cần khai báo: <uses-feature android :name= "android.hardware.camera" android :required= "false" /> <uses-feature android :name= "android.hardware.camera2" android :required= "false" /> Trong Activity thực hiện: Intent takePictureIntent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE ) ; if (takePictureIntent.resolveActivity(getPackageManager()) != null ) { startActivityForResult(takePictureIntent , CAMERA_REQUEST ) ; } else { } Chú ý cần tạo request code: private static final int CAMERA_REQUEST = 111 ; Xử lý kết quả sau khi chụp ảnh: @Override protected void onActivityResult ( int requestCode , int resultCode , Intent data) { super .onActivityResult(requestCode , resultCode , data) ; if (requestCode == CAMERA_REQUEST && resultCode == Activity. RESU
Nhận xét
Đăng nhận xét