androidcordovaphonegap-pluginschildbrowser

PhoneGap/Android, open ChildBrowser from .shouldOverrideUrlLoading()


I'm packaging a mobile website (over the network) in PhoneGap and would like to intercept certain links and open them using the ChildBrowser plugin. Is it possible to trigger ChildBrowser from native code (I've already determined which links to intercept)

I've tried below code but it results in NULLPointerException:

ChildBrowser childBrowser = new ChildBrowser();
childBrowser.openExternal(url, true);

Exception Details:

07-29 10:49:52.632      947-947/com.abc.androidTablet E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.phonegap.plugins.childBrowser.ChildBrowser.openExternal(ChildBrowser.java:127)
at com.mygola.androidTablet.abc_android$1.shouldOverrideUrlLoading(abc_android.java:96)
at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:270)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:372)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

Solution

  • At the end below code worked for me...

    ChildBrowser childBrowser = new ChildBrowser();
    childBrowser.cordova = this;
    childBrowser.showWebPage(url, null);