Take capture with camera, display image and save photos
I have been trying for a month to do a simple camera capture without success. This app I am developing works fine a few months ago, but since I upgrade Android to version 7 the app stops working correctly. I want to click a button, activate the camera (embed non api) after capturing to display the image in image viewer (high quality) and save the image in the pictures folder. then send the image to the server. In the existing version of my application, I was capturing the image, displaying the saved image in the image, and sending the server via json. Now the activity results are zero and the figurative image is empty :-( Please HELP
Old code that has worked fine for a while
public void onClick(View v) {
switch (v.getId()) {
case R.id.cancel_btn:
finish();
break;
case R.id.camera_btn:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Uri u = data.getData();
Log.d("u", String.valueOf(u));
theImageUriStr = String.valueOf(u);
Log.d("theImageUriStr", String.valueOf(theImageUriStr));
mImageView = (ImageView) findViewById(R.id.mImageView);
ALBUM_ART_URI = Uri.parse(String.valueOf(theImageUriStr));
Picasso.with(AddNewDish.this).load(ALBUM_ART_URI).into(mImageView);
}
else{
Log.d("mmmm", String.valueOf(resultCode));
}
}
The result I am getting from Log.du and the ImageUriStr is null
source to share
In 2017
the only realistic approach to camera in Android is the revolutionary library
https://github.com/gogopop/CameraKit-Android
It changed everything in Android development -
there is no other realistic approach.
Google (actually their office in Japan) has finally taken over responsibility for making the Android camera in real software. It was: https://github.com/google/cameraview . It was a miracle library that moved the camera from 10 to 5.
The flurgle library https://github.com/gogopop/CameraKit-Android is the first way out of the gate to finally fix all problems and make the camera work like normal software. The difficulty is now 1.
Do this to put a live camera in your application.
<com.flurgle.camerakit.CameraView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"/>
Do it to take photos
cameraView.setCameraListener(new CameraListener() {
@Override
public void onPictureTaken(byte[] picture) {
super.onPictureTaken(picture);
Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
save the image...
});
Everything is over. What is it.
Ten years of living hell with an Android camera is finally over.
source to share