Я создаю приложение для Android, которое делает несколько снимков. У меня есть следующее в методе onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sampling);
initLocalVariables();
}
private void initLocalVariables() {
this.sampleView = (ImageView) findViewById(R.id.sampleView);
this.startButton = (Button) findViewById(R.id.startSamplingButton);
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 1, this);
this.currentLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
this.paintBrush = new Paint();
this.paintBrush.setStyle(Style.FILL);
this.companyId = 0;
this.fieldId = 0;
this.plantSetId = 0;
this.standardRadius = 10f;
this.colorSelected = null;
this.sampleView.setOnTouchListener(this);
this.isSelectingPoint = false;
this.configureSample();
}
Метод initLocalVariables инициализирует локальные переменные и объекты и вызывает следующий метод.
private void configureSample() {
if (this.sampleList == null) {
this.sampleList = new ArrayList<Muestra>();
}
if (this.sampleList.size() == 0) {
this.currentSample = new Muestra();
this.currentSample.setIdMuestra(1);
this.currentSample.setIdEmpresa(this.companyId);
this.currentSample.setIdCampo(this.fieldId);
this.currentSample.setIdPanyo(this.plantSetId);
} else {
this.currentSample = this.currentSample.obtenerSiguienteMuestra();
if (this.currentLocation != null) {
this.currentSample.setUbicacion(new GeoLocation(this.currentLocation.getLatitude(), this.currentLocation.getLongitude(), this.currentLocation.getAltitude(),
this.currentLocation.getAccuracy()));
}
}
}
Как видите, currentSample не равен нулю. Я прошу систему сделать такой снимок.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
this.currentPicture = this.currentSample.obtenerSiguienteImagenMuestra(directorioAlmacenamiento);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, this.currentPicture.obtieneUriDesdeArchivo());
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
Делаю снимок и прошу сохранить в файловую систему. Изображение сохраняется, но при завершении сохранения приложение выдает следующее исключение.
Я не добираюсь до onActivityResult во время отладки. Это мой onActivityResult.
Чтобы начать процесс выборки, я делаю следующее.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
if (this.currentLocation == null) {
this.currentLocation = this.locationManager.getLastKnownLocation(LOCATION_SERVICE);
}
if (this.currentLocation != null) {
this.currentSample.setUbicacion(new GeoLocation(currentLocation.getLatitude(), currentLocation.getLongitude(), currentLocation.getAltitude(), currentLocation
.getAccuracy()));
}
Bitmap bitmap = currentPicture.convertToAndroidBitmap();
this.imageCanvas = new Canvas();
this.imageCanvas.setBitmap(bitmap);
this.sampleView.setImageBitmap(bitmap);
}
}
Есть предположения?
public void onClickStartSampling(View v) {
this.startButton.setVisibility(View.GONE);
this.sampleView.setVisibility(View.VISIBLE);
dispatchTakePictureIntent();
}
Спасибо!!!
Решено! Проверив опции разработки в телефоне, я обнаружил, что в конце списка опций стоит галочка «Нет действий по хранению». Это закрывало действие после запуска действия камеры, поэтому действие было нулевым, когда оно возвращалось после сохранения изображения.