Android Camera : data intent returns null

前端 未结 11 1696
不知归路
不知归路 2020-11-22 16:20

I have an android application which contains multiple activities.

In one of them I\'m using a button which will call the device camera :

public void         


        
11条回答
  •  误落风尘
    2020-11-22 17:05

    The following code works for me:

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, 2);
    

    And here is the result:

    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent)
    { 
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    
        if(resultCode == RESULT_OK)
        {
            Uri selectedImage = imageReturnedIntent.getData();
            ImageView photo = (ImageView) findViewById(R.id.add_contact_label_photo);
            Bitmap mBitmap = null;
            try
            {
                mBitmap = Media.getBitmap(this.getContentResolver(), selectedImage);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }
    

提交回复
热议问题