Android 如何阻止相机被意图打开
我需要在摄像机屏幕上显示一个警报对话框,以请求继续或退出摄像机。Android 如何阻止相机被意图打开,android,camera,android-camera-intent,Android,Camera,Android Camera Intent,我需要在摄像机屏幕上显示一个警报对话框,以请求继续或退出摄像机。 我使用了一个,它在摄像头屏幕上打开,在继续时我关闭对话框,但在退出时我需要关闭摄像头屏幕并返回到我的应用程序 我用这个意图打开相机 String fileName = "testphoto.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName);
我使用了一个,它在摄像头屏幕上打开,在继续时我关闭对话框,但在退出时我需要关闭摄像头屏幕并返回到我的应用程序 我用这个意图打开相机
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);
用于系统对话框的代码
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);
任何建议我该如何做。使用两种选择
onClick
onnoButton
:
finish()使用当前上下文编写>代码
setResult(Activity.RESULT.CANCELLED)代码>
检查此帖子[(单击此处)或[(单击此处)您是否可以提供系统对话框代码,其中您正在使用相机的“继续”和“关闭”按钮。