This is a migrated thread and some comments may be shown as answers.

problem with navigator.camera.getPicture

1 Answer 123 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
dmc_lat47
Top achievements
Rank 1
dmc_lat47 asked on 03 Nov 2014, 07:37 AM
I have a view with a data-model="App.models.artifacts" view model for artifacts.html that handles capturing and getting photos. I'm using requirejs to include kendo for the datasource.

/**
* artifacts data-model
*/
define([
    'kendo',
    'app/api'],
    function (kendo, api) {

        var viewModel = kendo.observable({

            dataSource: new kendo.data.DataSource({
                transport: {
                    read: function (options) {
                        api.getArtifactsForCurrentUser()
                        .done(function (data) {
                            options.success(data);
                        });
                    }
                }
            }),

            onUploadImage: function (e) {
                getPhoto(pictureSource.SAVEDPHOTOALBUM);
            },
            onCaptureImage: function (e) {
                capturePhoto();
            },
            onCaptureVideo: function (e) {
                captureVideo();
            },
            onCaptureAudio: function (e) {
                captureAudio();
            },

            uploadSuccess: function (e) {
                viewModel.dataSource.read();
                App.views.artifacts.refreshList();
            }

        });

at first tried creating the getPhoto method within the view model class, but it always performs a capture rather than a getPicture.  After hours of pulling my hair out as to why this was, and playing with the cordova camera sample, I finally got it running correctly by placing the getPhoto function in a separate jscript file that didn't have the kendo reference in it. I changed nothing about the call, except moving it.


/* camera.js */
.....
  function getPhoto(source) {
    // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source
    });
}   
.....

Why doesn't the call within the view model work correctly?
















1 Answer, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 04 Nov 2014, 02:22 PM
Hello,

I cannot see anything wrong with your code or any reason why this function will not work if you declare it in the view model. Also, I could not understand you completely. What do you mean by "it always performs a capture rather than a getPicture"? In your code I can see that you have both onCaptureImage which calls a capturePhoto function and onUploadPhoto that calls the getPhoto function. This is strange as getPicture() does not upload anything. Further, I don't know what these functions are bound to. If you want me to help you figure this out, please open a support ticket and send us your project, so that I can take a closer look.

I am looking forward to your reply.

Regards,
Martin Yankov
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussions
Asked by
dmc_lat47
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Share this question
or