Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How to get WebView object and Android context with Capacitor

$
0
0

Hi,

I am trying to implement Facebook App Events using their Hybrid app implementation guide.

In the Android section of the page, it gives this one line code that we have to add in the native app codebase.

AppEventsLogger.augmentWebView(<YOUR_WEBVIEW_OBJECT>, <YOUR_ANDROID_CONTEXT>)

To be honest, I have no clue on where to put this piece of code at but I started trying out in the file MainActivity.java in the onCreate() method.

Code placement aside, I also have no clue on how to obtain the WEBVIEW_OBJECT and ANDROID_CONTEXT function arguments.

Some of things I have tried are:

Context context = ((Bridge) bridge).getContext();
WebView webView = ((Bridge) bridge).getWebView();

Those lines didn’t produce any build errors but the app crashed as soon as it launches.

The errors I got are:

java.lang.RuntimeException: Unable to start activity ComponentInfo{io.ionic.starter/io.ionic.starter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context com.getcapacitor.Bridge.getContext()’ on a null object reference

java.lang.RuntimeException: Unable to start activity ComponentInfo{io.ionic.starter/io.ionic.starter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.webkit.WebView com.getcapacitor.Bridge.getWebView()’ on a null object reference

I have been scratching my head over this roadblock for a few days now. Can anyone help? I am sure it is something simple for someone seasoned in Android development.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>