Mobile Development 10.11 | webMethods Mobile SuiteWeb Help | Using webMethods Mobile Designer | Creating Mobile Application Projects | Coding a Mobile Application | Migrating to the New Run-Time Classes | Using the ImagePicker Class
 
Using the ImagePicker Class
The ImagePicker exposes two public static methods for general use, pickFromCamera(IImagePickerCallback callback) and pickFromGallery(IImagePickerCallback callback).
Note:
Activating the camera is a long-running task that can consume a lot of resources. Because of this, the mobile operating system may background or close applications. This includes the application that opened the camera in the first place. When control returns to the application, it will be via the IImagePickerCallback. Be aware that the application may not be in exactly the same state as before.
You should create an implementation of IImagePickerCallback for yourself. When the mobile operating system returns control to the application, either onImagePicked() or onImagePickingFailed() will be called. If the image picking has failed, the reason why will be indicated as an int value (currently one of error, user cancelled, or no permission), and a String with optional extra information that the operating system or the ImagePicker may provide. If no extra information is available, the String may be empty or null.
To create an IImagePickerCallback implementation, use the following code:
*In a method
ImagePicker.pickFromCamera(new MyImagePicker());
*In a separate class or as an inner class
class MyImagePicker
{
public onImagePicked(Image img)
{
System.out.println("Got an Image, " + img.getWidth() + "x"
+ img.getHeight());
//do something with the Image...
}

public onImagePickingFailed(int result, String error)
{
switch(result)
{
case STATUS_ERROR:
System.out.println("An unexpected error occured. Further info :"
+ error);
break;
case STATUS_CANCELLED:
System.out.println("The user closed the camera without taking a picture.");
break;
case STATUS_NO_PERMISSION:
System.out.println(
"The user / OS did not grant permission to use
the camera in this app, Further info : " + error);
break;
}
}
}