当单击屏幕上的按钮时,相机将被打开。关于这个问题,我看到堆栈溢出的帖子很少。我试过finish()
,finishActivity()
,onBackPressed()
方法dispatchTakePictureIntent();
在onClick
方法但是失败!它退出我的整个应用程序。如何返回上一个屏幕上的按下按钮
这是从摘录我full code:
巴顿的onClick
方法:
mCaptureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("TAG", "Camera opened");
dispatchTakePictureIntent();
}
});
此方法调度意图:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
photoURI = FileProvider.getUriForFile(this,
"com.pc.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
我的问题是,我怎么回去到前一个屏幕时,当我在C上按下后面的 按钮时amera的意图。
你必须什么也不做。 Android系统会为你处理。 –
但是当我按下相机模块中的按钮时,它会退出我的应用程序。 @NaweenNiroshan – Chip
检查AndroidManifest是否为您的活动设置了android:noHistory =“true”。 –