How to open native camera in ibm worklight

让人想犯罪 __ 提交于 2019-12-01 09:11:01

问题


Ibm Worklight have samples that calling the native app, but that was created in worklight itself eg: module_09_1_Android_CombiningNativeAndWebPages in this sample in android folder itself they creating one activity "com.AndroidShowNativePage.HelloNative" (package name) that activity was invoking from that javascript.

But, i need to call the native camera "com.android.camera" from the worklight is that possible ? if yes, please share your knowledge. Thanks in Advance!!


回答1:


Use this function in your applicaton. By default Cordova plugin is installed in worklight application. you need to just call its functionality

function takePicture() {

    navigator.camera.getPicture(
        function(data) {
            var img = dom.byId('camera_image');
            img.style.visibility = "visible";
            img.style.display = "block";
            //img.src = "data:image/jpeg;base64," + data;
            img.src = data;
            dom.byId('camera_status').innerHTML = "Success";
        },
        function(e) {
            console.log("Error getting picture: " + e);
            dom.byId('camera_status').innerHTML = e;
            dom.byId('camera_image').style.display = "none";
        },
        { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType : navigator.camera.PictureSourceType.CAMERA});
};



回答2:


Why write code that will work on Android and not on iPhone? Worklight uses PhoneGap, so you can use camera.getPicture and get to your application the image taken with the camera as base64.

navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );

See PhoneGap documentation for more information (http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html).



来源:https://stackoverflow.com/questions/11900361/how-to-open-native-camera-in-ibm-worklight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!