我正在尝试使用 android 相机拍照并告诉它保存到手机的图库中。我想我在路上搞砸了,但我似乎找不到我的错误。有人可以帮助我吗?我对android非常陌生。
调用摄像头的代码
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String uriToFileInExternalStorage = null;
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriToFileInExternalStorage);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
处理照片并告诉它去画廊的代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
//check if camera has taken picture by checking request code
Toast.makeText(MainActivity.this, "Photo Captured", Toast.LENGTH_SHORT).show();
Uri mPath=data.getData();
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(mPath);
this.sendBroadcast(mediaScanIntent);
}
}