【发布时间】:2017-06-10 21:51:22
【问题描述】:
我的应用中有一个按钮,它必须是打开相机,这是我的代码:
mPhotoButton = (ImageButton) v.findViewById(R.id.crime_camera);
final Intent captureImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
boolean canTakePhoto = mPhotoFile != null &&
captureImage.resolveActivity(packageManager) != null;
mPhotoButton.setEnabled(canTakePhoto);
if (canTakePhoto) {
Uri uri = Uri.fromFile(mPhotoFile);
captureImage.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
mPhotoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(captureImage, REQUEST_PHOTO);
}
});
当我按下它时,应用程序崩溃了。
如果使用createChooser(),在运行应用程序并按下按钮时,打开选择相机应用程序的对话框,它不会打开相机应用程序并且应用程序崩溃。
我在清单中定义了相机的权限。
此代码运行在另一台设备上,但在我的设备上运行时 (Galaxy S7 API24) 发生错误。
【问题讨论】:
标签: android android-intent camera