How can i send data from Java Script to gwt Coding using JsInerop.

瀏覽次數:69 次
跳到第一則未讀訊息

cRaZy cRuZz

未讀,
2018年4月11日 凌晨1:55:182018/4/11
收件者:GWT Users
Here it is ...!

-->I am calling cordova implementation from this coding. 

//Handles imageCapture icon 
final Image cameraIcon = new Image(ImageNameConstants.CAMERA);
cameraIcon.setStylePrimaryName(StyleConstants.CONDITION_IMAGE);  
cameraIcon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Log.debug("onClick");
if (!isReadOnly() && isEditable()){
if (ClientSettings.isMobileNative()){
     imageData = imageCapture(); //This  might wrong iam not getting data.
FileContent fileContent = new FileContent();
if (imageData != null){
fileContent.setFileContent(imageData.getBytes());      
    FileRPCServiceAsync cameraRpc = ServiceFactory.getService(FileRPCService.class, FileContent.class);
cameraRpc.saveFile(fileContent,
new BaseAsyncCallback<FileContent>(messagePresenter) {
    @Override
public void handleSuccess(FileContent file) {
   
}
@Override
public boolean handleException(Throwable caught) {
Log.error("Error in saving file status:"
+ ErrorMessageHandler.stringify(caught));
return true;
}
});
}
}

                     private  native  String imageCapture()/*-{
if ($wnd.isImageSupported()){
return $wnd.imageCapture();
}else{
//var imageCaptureWidget = $doc.getElementById();
alert("NO-image");
}
}-*/;
});

-->This my JS code.

function isImageSupported(){
var supported = true;
return supported;
}
function imageCapture(){
if(isImageSupported()){
try {
        navigator.camera.getPicture(onSuccess, onFail, {
        quality: 50,
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA
    });
    function onSuccess(imageData) {
   
        return imageData;
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }
} catch(e){
alert("CAPTURE-ERROR-Works On Mobile Devices Only.");
  }
   }

please some one help me after taking image i need that base64 string in js to  java async call, how to achieve this by using jsInterop.

Colin Alworth

未讀,
2018年4月13日 中午12:12:312018/4/13
收件者:GWT Users
Your Java code isn't async, but your JSNI method and JS function are - the imageCapture() method is passing an async function to `navigator.camera.getPicture`, and expected it to return right away. Instead, your `imageCapture` method should take a java-annotated @JsFunction and pass that in place of onSuccess (and probably onFailure too).
回覆所有人
回覆作者
轉寄
0 則新訊息