-2

I need to show a Alert dialog on camera screen to ask for continue or exit camera.
I used a system dialog, it open on camera screen, on continue i close the dialog, but on exit i need to close the camera screen and back to my app.

I'm using this intent for for opening camera

String fileName = "testphoto.jpg";
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
        imageUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, Constants.SELECT_CAMERA_PHOTO);

Code used for system dialog

             final WindowManager manager = (WindowManager) getActivity().getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                layoutParams.gravity = Gravity.CENTER;
                layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
                layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
                layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
                layoutParams.alpha = 1.0f;
                layoutParams.packageName = getActivity().getPackageName();
                layoutParams.buttonBrightness = 1f;
                layoutParams.windowAnimations = android.R.style.Animation_Dialog;

                final View view = View.inflate(getActivity().getApplicationContext(),R.layout.system_alert_dialog, null);
                ButtonFlat yesButton = (ButtonFlat) view.findViewById(R.id.cancel_button);
                ButtonFlat noButton = (ButtonFlat) view.findViewById(R.id.confirm_button);
                TextView message = (TextView)view.findViewById(R.id.title_text);

                message.setText("Click you first image to see how it works.");

                yesButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        manager.removeView(view);
                    }
                });
                noButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        manager.removeView(view);
                       //==here camera should close==
                    }
                });
                manager.addView(view, layoutParams);

Any suggestion how can i do it.

Community
  • 1
  • 1
Ankit
  • 483
  • 7
  • 24
  • check this post [http://stackoverflow.com/a/19947081/2715073] (click here) OR [http://www.wsdl2code.com/pages/home.aspx] (click here) – Pankaj May 22 '15 at 07:37
  • Can you provide system dialog code where you are using continue and close buttons for camera. – Garima Mathur May 22 '15 at 07:38

1 Answers1

0

Use 2 alternatives onClick on noButton:

  1. Set finish(); with use of current context.
  2. Set setResult(Activity.RESULT.CANCELLED);
Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
Garima Mathur
  • 3,312
  • 3
  • 18
  • 32