Android open camera from button

前端 未结 10 1596
無奈伤痛
無奈伤痛 2020-11-29 03:24

I hope this isn\'t a duplicate question but I am making an app that I want a button to open the camera app (the default android camera separately). How do I got about doing

10条回答
  •  伪装坚强ぢ
    2020-11-29 03:56

    public class camera_act extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_camera_act);
             ImageView imageView = findViewById(R.id.image);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent,90);
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode,resultCode,data);
           Bitmap bitmap = data.getExtras.get("imageKey");
           imageView.setBitmapImage(bitmap);
                
            }
        }
    }
    

提交回复
热议问题