我需要在相机屏幕上显示一个警告对话框,要求继续或退出相机 我使用了system dialog,它在相机屏幕上打开,继续我关闭对话框,但在退出时我需要关闭相机屏幕并返回我的应用程序。
我正在使用此意图打开相机
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);
任何建议我该怎么做。
答案 0 :(得分:0)
在noButton
上使用2个替代finish();
:
setResult(Activity.RESULT.CANCELLED);
。next.titleReceived == titleF.text