Android how to process photo - android

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.

Related

How can I skip an activity created by androids CAMERA_ACTIVITY?

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.

Barcode app Scan result display on screen

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);

Android Zxing (barcode library). How to change the after scan intent

I am developing an Android application, I need to embed the Zxing scanner. The application should allow the user to scan a QR Code and then store the QR code ID of the product and parse it from an XML file. As yet, I have used the simple code:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(getPackageName());
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
What this code does is, scans the product and bring me back to the previous screen of my app. I haven't included the entire library from Zxing as I wanted the Barcode scanner to handle it, but it seems I have to do more than I already have done.
You need to make an onActivityResult method that will get the callback once barcode scanner is done. Inside there you will handle the code string and do whatever you like with it.
/*Here is where we come back after the Barcode Scanner is done*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
// contents contains whatever the code was
String contents = intent.getStringExtra("SCAN_RESULT");
// Format contains the type of code i.e. UPC, EAN, QRCode etc...
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
Log.i("TAG",format + "\t" + contents);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel. If the user presses 'back' before a code is scanned.
Log.i("TAG","Canceled");
}
}
}
This example just logs the results, you'll need to expand upon it to do whatever you want with the info you get back from the scanner.
Better still, use the IntentIntegrator class supplied with the project. It wraps up all the details listed here and its documentation already tells you exactly how to integrate it into your app. It deals with things for you like getting the app installed if not already.

Android - Camera Image Not always saving

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.

Android SDK - Reference the phone's gallery app?

As of right now, in my app I have created a rudimentary gallery app using the provided widget, I need this to select a picture from the phone. This is working fine and everything, but lacking very much in presentation.
I've got a couple apps on my phone that do the same thing, but they somehow use the gallery that's already in the phone to let the user select an image. FourSquare, for example, when you select an image to use as your picture, it loads the gallery and asks you to select an image.
How is this possible? I've scoured the internet for the last couple and have come up empty handed.
To get an image from the standard gallery you can do:
private static final int MEDIA_IMAGE_REQUEST_CODE = 203948; // This can be any unique number you like
Intent getImageFromGalleryIntent =
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(getImageFromGalleryIntent, MEDIA_IMAGE_REQUEST_CODE);
Then to receive the image once the user has chosen one:
protected final void onActivityResult(final int requestCode, final int resultCode, final Intent i) {
super.onActivityResult(requestCode, resultCode, i);
if(resultCode == RESULT_OK) {
switch(requestCode) {
case MEDIA_IMAGE_REQUEST_CODE:
// Get the chosen images Uri
Uri imageUri = i.getData();
// Load the bitmap data from the Uri
// It is probably best to do this in an AsyncTask to avoid clogging up the Main Thread
break;
}
}

Categories

Resources