В своем приложении для работы с камерой я использую библиотеку Fotoapparat версии 2.4.0 .Приложение тестируется на платформе Android 4.3 . Проблема в том, что после первого снимка камера перестает делать снимки.
Код:
public class NewPostFragment extends Fragment implements View.OnClickListener {
private CameraView mCameraView;
private RecyclerView mPhotosRecyclerView;
private PhotoRibbonAdapter mPhotoRibbonAdapter;
private ImageButton mTakePhotoButton;
private Toolbar toolbar;
private Fotoapparat mFotoapparat;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_post, container, false);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
mPhotosRecyclerView = view.findViewById(R.id.preview_photos);
mCameraView = view.findViewById(R.id.camera_view);
mTakePhotoButton = view.findViewById(R.id.take_photo_button);
toolbar = view.findViewById(R.id.camera_toolbar);
mTakePhotoButton.setOnClickListener(this);
mPhotosRecyclerView.setLayoutManager(layoutManager);
mPhotoRibbonAdapter = new PhotoRibbonAdapter();
mPhotosRecyclerView.setAdapter(mPhotoRibbonAdapter);
mFotoapparat = Fotoapparat
.with(getContext())
.into(mCameraView)
.build();
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onStart() {
super.onStart();
mFotoapparat.start();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.take_photo_button :
PhotoResult photoResult = mFotoapparat.takePicture();
photoResult.toBitmap().whenDone(new WhenDoneListener<BitmapPhoto>() {
@Override
public void whenDone(@org.jetbrains.annotations.Nullable BitmapPhoto bitmapPhoto) {
//The second time, the bitmapPhoto parameter is null!
if (bitmapPhoto != null) {
mPhotoRibbonAdapter.add(bitmapPhoto.bitmap);
mPhotoRibbonAdapter.notifyDataSetChanged();
}
}
});
break;
}
}
Также я заметил, что после первого снимка камера и все приложение начинает замедляться.