i am trying for month to make simple camera capture with no success. This app i am developing was working great few months ago, but since i update android to version 7 the app stop working correct. I want to click a button, activate the camera (build in not api) after capture to display the image in imageview (in high quality) and save the image to the pictures folder. after that to send the image to server. In the existing version of my app, i was capture the image, display the saved image in the imageview and send to server via json. Now the activity results is null and the imageview is empty :-( Please HELP
Old code that work great 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.d u and theImageUriStr is null
For 2017,
the only realistic approach to camera in Android is the revolutionary library
It has changed everything in Android development -
there is no other realistic approach possible.
Google (actually their Japan office) finally took it upon themselves to write something that makes android camera into actual software. That was: https://github.com/google/cameraview . That was a miracle library which took camera difficulty from 10 to 5.
The flurgle library https://github.com/gogopop/CameraKit-Android is the first out of the gate to finally resolve all problems and make the camera work like normal software. Difficulty is now 1.
Do this to put a live camera in your app
<com.flurgle.camerakit.CameraView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"/>
Do this 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...
});
It's all over. That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With