Using intent to use Camera in Android

后端 未结 5 1636
栀梦
栀梦 2021-02-14 19:02

I am using the following code to use camera by using intent. In the parameter of intent I am passing android.provider.MediaStore.ACTION_IMAGE_CAPTURE. It is able to

5条回答
  •  后悔当初
    2021-02-14 19:29

    I have used the following code and it worked!

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
        }
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            final Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            im.setImageDrawable(null);
            im.destroyDrawingCache();
            Bundle extras = data.getExtras();
            Bitmap imagebitmap = (Bitmap) extras.get("data");
            im.setImageBitmap(imagebitmap);
        }
    
    }
    

提交回复
热议问题