0

I have a webview in a fragment and have my own Bridgecallback services.

I have a javascript file TriggerEventsService.js

define(function(require){

    var Service = require('BridgeService');
    var TriggerEventsService = new Service({
        name: "TriggerEventsService",
        timeout : 3000
    });

    //Public API
    TriggerEventsService.postHibernate = function(){
        this.execute("postHibernate", {"event" : "App becoming inactive"}, function(){}, function(){});
    };

In my HTML file index.html

  function postEventHibernate(){
            require(['TriggerEventsService'], function(ui){
                ui.postHibernate();
            });
        }

Can I call this function directly from native android methods ?

In iOS I have done this:

    NSString *jsString = [NSString stringWithFormat:@"require(['TriggerEventsService'],
 function(ui){ui.postHibernate();});"];
             [self.webView evaluateJavaScript:jsString completionHandler:nil];

and It works fine !I know a way to do it in iOS , figuring anyone can help me out if android has any direct method ?

I have seen other Answers but was not sure how to call the my TriggerEventsService.js - webview.loadUrl("WHAT EXACTLY SHOULD I CALL HERE ?");

2

1 Answer 1

1

I have seen other Answers but was not sure how to call the my TriggerEventsService.js - webview.loadUrl("WHAT EXACTLY SHOULD I CALL HERE ?");

Assuming that postEventHibernate() is a global JavaScript function, this would be:

webview.loadUrl("javascript:postEventHibernate();");

FWIW, this is covered in my book, though most of this specific material is in the preview edition of my advanced WebView chapter.

Sign up to request clarification or add additional context in comments.

1 Comment

Ahhh I was trying webview.loadUrl("javascript:postEventHibernate()"); just a semi column away from 8 hours!! Thanks A lot ! Resolved by:- webView.setWebViewClient(new WebViewClient(){ public void onPageFinished(WebView view, String url){ webView.loadUrl("javascript:postEventHibernate();"); } });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.