I'm making an android and ios app using kony and I want to be able to import an image from the phone's library (jpeg or png).
I have the function for my import button here:
this.control("btnImportPicture").onClick = function (button) {
// Insert solution here
};
The name of my image widget (which I want to set to the selected image) is imgUser
Problem is I have no idea what to do for my btnImportPicture
button onClick
function
Edit:
I have seen that you can use the following in the onClick
function:
var config = {
selectMultipleFiles: false,
filter: ["image/png", "image/jpeg"]
};
kony.io.FileSystem.browse(config, selectedFileCallback);
But I have no idea what to do for the selectedFileCallback
, currently it just crashes everytime I click the button.
I got an answer on the kony forums and thought I better share it here in-case anyone else runs into this issue.
kony.io.FileSystem.browse API is applicable for only Desktopweb Platform. it will not work in Mobile richclient applications.
we can use "kony.phone.openMediaGallery" API. The main usecase of this API is to open the gallery of the phone and to pick any image. Once we select any image then onselectioncallback function will trigger with image rawBytes as input parameter . we can use this rawBytes in our Application either to display image on the image Widget or for other usecases
Please refer below documentation link.
Put this in your onClick:
function openGallery()
{
var querycontext = {mimetype:"image/*"};
var returnStatus = kony.phone.openMediaGallery(onselectioncallback, querycontext);
}
function onselectioncallback(rawbytes)
{
if (rawbytes == null)
{
alert("Please select an Image");
return;
}
frmone.image26850851102837.rawBytes=rawbytes;
}
Note : we can select only one image at a time.