onActivityResult returned from a camera, Intent null

前端 未结 7 791
执念已碎
执念已碎 2020-12-06 04:41

I follow the instruction on Camera on Android dev site

I just start the Camera Intent, not build my own camera.

The sample code to handle result return afte

7条回答
  •  余生分开走
    2020-12-06 05:21

    Try this code below.....

    btn_capture.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
    
                Intent cameraIntent = new  Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent, CAMERA_REQUEST); 
            }
        });
     protected void onActivityResult(int requestCode, int resultCode, Intent data){
    
    
                 if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
                     Bitmap photo = (Bitmap) data.getExtras().get("data"); 
                     img.setImageBitmap(photo);
                 } 
              }
    
        }
    

    Then finally you add below code to your manifest

        
    

提交回复
热议问题