Page tree
Skip to end of metadata
Go to start of metadata

Smartface allows you to access the most of device information and you can use this information in your application such as Gallery.

Device Multimedia

You can access device’s gallery (images, videos and sounds (only available for Android) with only typing:

SMF.Multimedia

See also: SMF.Multimedia in the docs.

Getting gallery items

This method allows you to get all gallery items from device. In example as below :

var img = new SMF.UI.Image();

SMF.Multimedia.getGalleryItems({
    type: [SMF.Multimedia.MediaType.IMAGE, SMF.Multimedia.MediaType.VIDEO],
    onSuccess: function(e) {
        img.image = e[0].file;
        alert("success");
    },
    onError: function() {
        alert("fail");
    }
});

Pick an image(pick from gallery)

It opens the Device Gallery and you can select any media item. Info related to the media item will be returned in callback function. In example as below :

var img = new SMF.UI.Image();

SMF.Multimedia.pickFromGallery({
    type: [SMF.Multimedia.MediaType.IMAGE, SMF.Multimedia.MediaType.MOVIE, SMF.Multimedia.MediaType.SOUND],
    onSuccess: function(e) {
        img.image = e.file;
        alert(e.filename); //print file name on the screen via alertbox
    },
    onCancel: function(e) {
        alert("cancelled");
    },
    onError: function(e) {
        alert("failed");
    }
});

Saving an image(save to gallery)

After taking a picture by using camera function of your device you can save it to the device gallery with this method. In example as below :

var img = new SMF.UI.Image();


SMF.Multimedia.saveToGallery({
    item: img.image,
    name: "IMG_NAME",
    onSuccess: function(e) {
        alert("Image saved to " + e.path);
        alert("Image name: " + e.name);
    },
    onError: function(e) {
        alert("error");
    }
});

Also here is an example of opening the camera and taking a picture to save to the gallery as below :

var photoUri = "";
SMF.Multimedia.startCamera(1, 2, 1,
    function(e) {},
    function(e) {
        photoUri = e.photoUri;
        SMF.Multimedia.saveToGallery({
            item: photoUri,
            name: "myPhoto.jpg",
            onSuccess: function(e) {
                alert("Image saved to gallery.");
            },
            onError: function() {
                alert("error");
            }
        });
    },
    function(e) {},
    function(e) {}
);