Using intent to use Camera in Android

后端 未结 5 1623
栀梦
栀梦 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);
        }
    
    }
    
    0 讨论(0)
  • 2021-02-14 19:34

    Try request code 1337.

    startActivityForResult(cameraIntent , 1337);
    
    0 讨论(0)
  • 2021-02-14 19:45

    do you have the following declarations in your manifest ?:

    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    

    ?? I used to do the same... here is my call to intent:

    File file = new File( _path );
        Uri outputFileUri = Uri.fromFile( file );
    
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
        intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
        intent.putExtra( MediaStore.EXTRA_VIDEO_QUALITY,1);
    

    the only slight difference between my and your code - I have file path in URI sending among call

    0 讨论(0)
  • 2021-02-14 19:49

    Using intent to use Camera in Android

    ##

       Uri imageUri;
    1:- 
    
         TextView camera = (TextView)findViewById(R.id.camera);
             camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    
                final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File photo = new File(Environment.getExternalStorageDirectory(), new Date().getTime() + "myPic.jpg");
                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(photo));
                imageUri = Uri.fromFile(photo);
                startActivityForResult(cameraIntent, IMAGE_CAMERA_REQUEST);}
    
    
    2:-
    
    
    
            @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(requestCode, resultCode, data);
                    try {
    
                        if (requestCode == IMAGE_CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
                            Uri selectedImage = imageUri;
                            getActivity().getContentResolver().notifyChange(selectedImage, null);
                            ContentResolver contentResolver = getActivity().getContentResolver();
                            Bitmap bitmap;
                            try {
                                bitmap = android.provider.MediaStore.Images.Media
                                        .getBitmap(contentResolver, selectedImage);
    
                                imageDialog(bitmap);
                            } catch (Exception e) {
    
                                Log.e("Camera", e.toString());
                            }
    
                        }
        }
        }}
    
    I hope it's working for you.
    
    0 讨论(0)
  • 2021-02-14 19:52

    This how I use it

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, 1337);
    
    0 讨论(0)
提交回复
热议问题