NeelamGoyal
NeelamGoyal

Reputation: 41

How to show camera on android gallery?

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); 
startActivityForResult(i, 2); 

When I use these line for select image from my device gallery then by default cancel button is display on title bar of my device gallery screen. On the place of cancel button I want that display Camera Image Please Can any one suggested me that how to show camera

Upvotes: 0

Views: 156

Answers (2)

Dakshesh Khatri
Dakshesh Khatri

Reputation: 629

frmcamera.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent cameraIntent = new Intent(
                            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(cameraIntent, 1);

                }
            });
            frmalbumb.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent int_album = new Intent(Intent.ACTION_PICK);
                    int_album.setType("image/*");
                    startActivityForResult(int_album, 2);

                }
            });




            @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {

            Bitmap photo = (Bitmap) data.getExtras().get("data");
            imgview.setImageBitmap(photo);

        } else if (requestCode == 2 && resultCode == RESULT_OK) {

            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            File file = new File(picturePath);
            Bitmap bmpp = decodeAndResizeFile(file);
            imgview.setImageBitmap(bmpp);


        }
    }



    public Bitmap decodeAndResizeFile(File f) {
        try {
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f), null, o);

            // The new size we want to scale to
            final int REQUIRED_SIZE = 70;

            // Find the correct scale value. It should be the power of 2.
            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 1;
            while (true) {
                if (width_tmp / 2 < REQUIRED_SIZE
                        || height_tmp / 2 < REQUIRED_SIZE)
                    break;
                width_tmp /= 2;
                height_tmp /= 2;
                scale *= 2;
            }
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {
        }
        return null;
    }

Upvotes: 1

GrIsHu
GrIsHu

Reputation: 23638

AFAIK Camera applications layout are independent of the other application's . It will changed according to the devices as well as the API. You can not change the design of the layout of the default camera application.

If you want then you can create your own layout and open the camera on your own.

Upvotes: 0

Related Questions