Android How can I call Camera or Gallery Intent Together

后端 未结 7 1787
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 09:27

If I want to capture image from native camera, I can do:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTR         


        
7条回答
  •  星月不相逢
    2020-12-02 10:06

    Create a button in your XML layout and the add the attribute android:onClick="takeAPicture" then in your main activity create a method with the same name from the onClick attribute.

    public void takeAPicture(View view){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            startActivityForResult(intent, IMAGE_CAPTURE);
    }
    

    And just do another method for when you want to get the image from the gallery:

    public void getImageFromGallery(View view) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,
                        "Select Picture"), SELECT_PICTURE);
    } 
    

提交回复
热议问题