I'm using androids default camera capture and then a crop library to take a photo then crop it to a square to be displayed on the next layout, the picture stored on the device and a record created on a database.
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image_file));
startActivityForResult(camera_intent, CAM_REQUEST);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==2 || requestCode == 6709) {
if (resultCode == RESULT_CANCELED) {
} else if (resultCode == RESULT_OK) {
//Crop.pickImage(this);
if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
//doSomethingWithCroppedImage(outputUri);
setResult(resultCode);
} else {
File cropme = new File(tempPicture[4]);
if (Build.VERSION.SDK_INT >= 24) {
try {
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
new Crop(Uri.fromFile(cropme)).output(Uri.fromFile(cropme)).asSquare().start(this);
}
}
}
The problem is there is a picture confirmation page as shown below that's redundant and will save the user a lot of time if I'm able to remove it.
How can I go about either editing the default camera capture activity or using another camera template online?
I'd like to make process as efficient as possible so if there's a better way of doing this let me know.
The problem is there is a picture confirmation page as shown below that's redundant and will save the user a lot of time if I'm able to remove it.
Do not use ACTION_IMAGE_CAPTURE. Use the camera APIs directly (e.g., android.hardware.Camera, android.hardware.camera2.*) or via a library that wraps them (e.g., CameraKit-Android, Fotoapparat).
How can I go about either editing the default camera capture activity
There are ~10,000 Android device models. These ship with dozens, if not hundreds, of different camera apps. Plus, users install their own. Any of those can respond to ACTION_IMAGE_CAPTURE. Whether any of them have a confirmation screen is up to the developers of those apps, not you. If you want complete control over the camera experience, do not delegate photo-taking to ACTION_IMAGE_CAPTURE, but write your own camera code.
Related
My application is a portrait locked application. The application structure is based on one activity and multiple fragments. I am using support v4 fragments for this and fragments has nesting also. While I am trying to take pictures from the camera, for my profile update fragment. The camera app is open and I can capture and save the image. the image is getting in the onActivityResult() successfully.
But randomly the application orientation is getting distorted and its automatically change to landscape.Because of that, the current fragment state is missing. I locked the orientation from Manifest file as android: screenOrientation="portrait for my activity. This issue is mainly getting in Custom android phone (Samsung, HTC etc). I required a directional guideline, whether I need to create a custom camera or any alternate fix for this issue.
My Camera call method from my fragment is given below:
private void callCamera() {
try {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}catch (Exception e){
e.printStackTrace();
}
}
And I am getting the result in onActivityResult() of my Fragment as like this
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if( requestCode == CAMERA_REQUEST && resultCode == mActivity.RESULT_OK){
/**
* For Default Camera callback
*
*/
Bitmap image = (Bitmap) data.getExtras().get("data");
if(image != null){
AppUtility.mCapturedImage = image;
mIvProfileImg.setImageBitmap(image);
}
}
}
Simple solution will be handle it in onSaveInstanceState method.you cannot control camera intent rotation.setting your rotation to portrait and take picture in landscape mode it rotates your activity forcefully it loses its state.
I am trying to make a barcode scanning app. I am stuck at the point where I am able to scan the barcode but now I want to show the barcode image along with decoded barcode number and other details on the screen and then provide a button to proceed to next screen. How should I go about it? I am unable to understand should I call an intent to new activity or the layout view. If I call the new activity, how do I pass the barcode that's decoded and other details to new activity?
Help.
Want something like this after scanning a barcode:
you can get and use that barcode anywhere, as:
uid is a textview where i have added the result from ZXing (Zebra Crossing) library activity.:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
Log.e("test 1",String.valueOf(requestCode));
if (resultCode == RESULT_OK) {
Log.e("test 2",intent.getStringExtra("SCAN_RESULT_FORMAT"));
Log.e("test 3",intent.getStringExtra("SCAN_RESULT"));
Toast.makeText(getApplicationContext(), intent.getStringExtra("SCAN_RESULT"), Toast.LENGTH_LONG).show();
uid.setText(intent.getStringExtra("SCAN_RESULT")) ;
} else if (resultCode == RESULT_CANCELED) {
Log.e("test 4",String.valueOf(requestCode));
}
}
}
Over Image you are seeing in sample image is a generated barcode not a actual picture captured from the camera.
For this you can use iText is a great Java PDF library. They also have an API for creating barcodes. You don't need to be creating a PDF to use it.
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
I'm developing an app using a camera intent to take a photo and an image view to show it. I've two problems, first is with the camera.
I have an activity only to manage the camera behaviour, the code of this manager is based on the sample of developer.google.com.
The issue is on the camera interface.
When I open the camera on vertical position, take a photo and accept de preview, all the process on vertical position, all works fine. The same behaviour with horizontal position.
But If accepts the photo preview in a different position how was started the camera interface, don't ends. It seems like the camera were restarted and I can take another photo.
In addition, when this occurs the photo is not saved correctly, on gallery I don't see the picture, has a message 'Couldn't load photo'.
My other problem it's similar, but this time occurs on an ImageView. When I have the ImageView setted with an image, after rotate my device the image disappears.
This issue only occurs when I've taken a new photo, if the image is already in system all works fine.
EDIT:
static final int REQUEST_IMAGE_CAPTURE = 1;
OnClick {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = null;
try {
f = createImageFile();
mCurrentPhotoPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
} catch (IOException ex) {
ex.printStackTrace();
mCurrentPhotoPath = null;
}
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
OnActivityResult {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
if (mCurrentPhotoPath != null) {
galleryAddPic(); //Method to save the pic in the gallery
finishActivity();
} else {
Log.e("ActivityResult", "Photo path is null");
}
} else if (resultCode == RESULT_CANCELED) {
finishActivity();
}
}
EDIT 2: I just resolve the second issue, I'm beginner on developing apps and I don't knew that rotate the device restarts the interface and all modifications on the data after OnCreate should be saved on OnSaveInstanceState.
Now I only have one problem. I try it the strange behaviour in other device and it's the same.
I am working on an android camera-based app with use of Intent. After capturing a photo I can see that photo and two buttons appear - "Save" and "Cancel". What I want to do is to not wait for user to choose one of these two buttons, but start processing this photo and then depending on the result of processing do futher actions.
I've been doing it this way so far :
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
protected void startCameraActivity()
{
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
// the method below is my method for setting proper path for my image file
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
startActivityForResult( intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE );
}
this method is invoked when I launch my app. So I start my app with camera.
Then I take a photo. And I can choose "Save" or "Cancel". When I choose one this method is invoked :
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
onPhotoTaken(); // processing...
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
}
After receiving proper resultCode I load that image from file and then start processing it.
And now my quesiton is : If I can get that image before onActivityResult method is invoked? It is invoked after clicking on one of these buttons.
( I want to do it the similar way google googles does it - user captures a photo and that photo is being processed right away )
You're going to need to implement your own picture taking activity, something along the lines of this (which includes source code at the end of the page).
It takes some time to set it up straight, compared to using simple Intent, but after that you have direct access to all camera features, including camera image even before it's made available to the calling activity.
I used this page: http://developer.android.com/guide/topics/media/camera.html
To learn how to use the existing camera app to take a photo & return a result for my app.
Sometimes the image saves, sometimes it doesn't. I'm testing on a Samsung Galaxy Tablet (8.9). If I leave the resolution at the highest setting (2048x1536) & take the photo in portrait, the image never saves. If I take the photo in landscape, the image saves most of the time. If I reduce it to 1024x768, the image saves most of the time (whether portrait or landscape).
Looking for a direction to figure this one out.
private void startCameraForCapture() {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE, getApplicationContext()); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
} catch (Exception e) {
// TODO Auto-generated catch block
_errorMessageTitle = "Error 'StartCamera'";
_errorMessage = "Error: " + e.toString();
showDialog(DIALOG_ERROR_GENERAL);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
showPhoto(2);
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
_errorMessageTitle = "Error in 'Take Photo'";
_errorMessage = "Image Capture Failed";
showDialog(DIALOG_NOTICE_GENERAL);
}
}
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "Video not yet supported", Toast.LENGTH_LONG).show();
// Video captured and saved to fileUri specified in the Intent
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the video capture
} else {
// Video capture failed, advise user
}
}
}
Sorry, should have resolved this a while back. The problem was my being a noob to Android.
In the OnCreate method I had a function that was deleting files from the Temp folder I used to store the images from the photo (I added in OnCreate for cleanup purposes).
I found out that OnCreate gets called again when there is an orientation change.
On some Samsung devices, the camera rotates the screen from portrait (which was the only orientation that I was allowing in my app) to landscape.
When the photo was taken, depending on if the user rotated their device prior to selecting "Save Image", the orientation was changing.
Since the orientation was changing, the function I used to delete the temp files was being called. Felt pretty dumb after I figured it out.