November 22, 2016

TypeError: h.apply is not a function

This is a Knockout JS error. I faced this issue when I am trying to invoke click action of a link created. My link statement is like below.

<a data-bind="attr:{id:Reqid},text: Title,click: $('#popup1').ojPopup('open', '#btnTitle')"></a>

And on click of this link, I am getting the below error.

TypeError: h.apply is not a function

This is because the click handler needs to be wrapped within a function. Below updated statement resolved the issue.

<a data-bind="attr:{id:Reqid},text: Title,hover: function(){$('#popup1').ojPopup('open', '#btnTitle')}"></a>

November 1, 2016

How to open device camera or picture gallery from MAF app

MAF provides a device feature method getPicture() to open the device camera or picture gallery. You can create binding to it if you want to open camera on the app. But if you want to handle this from java code in MAF, then check the below post.

Below is the code should be used to access the camera from the java code in MAF.

DeviceManager dm = DeviceManagerFactory.getDeviceManager();

This method returns a string value with either base46 encoding string or the file path of the image based on the given destination type.

Syntax of the method is:
getPicture(int quality, int destinationType, int sourceType, boolean allowEdit, int encodingType, int targetWidth, int targetHeight) 


quality: Quality of saved image
destinationType: Type of the return value whether it is base64 encoding string or file path. For base64 use 0=DESTINATIONTYPE_DATA_URL or for file path use 1 = DESTINATIONTYPE_FILE_URI
sourceType: What is the source of the picture whether it is device camera or photo gallery. For gallery use 0=CAMERA_SOURCETYPE_PHOTOLIBRARY or for camera use 1=CAMERA_SOURCETYPE_CAMERA
allowEdit: Allow simple editing of image before selection
encodingType: the encoding of the returned image file. Select 0 = CAMERA_ENCODINGTYPE_JPEG for JPEG image or 1 = CAMERA_ENCODINGTYPE_PNG for PNG image
targetWidth: Width in pixels to scale image
targetHeight: Height in pixels to scale image

Note: you can not test camera in iOS Simulator or Android Emulator. The camera can be tested only on the device, but you can test the gallery in the Simulator or Emulator. To check if the running device is Simulator or Emulator, you have to give a condition like,

if (dm.getName().indexOf("Simulator") != -1)  // For iOS Simulator
if (dm.getName().indexOf("sdk") != -1)            //For Android Emulator