當單擊屏幕上的按鈕時,相機將被打開。關於這個問題,我看到堆棧溢出的帖子很少。我試過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」。 –