IBM Worklight - How do I enable WebView debugging in Android?
Asked Answered
T

1

7

Since Chrome has an awesome feature for remote debugging, I am wondering how this could help in developing in Worklight.

In the following docs they say to debug the contents of your WebView, you need to enable it programmatically from within your application by calling setWebContentsDebuggingEnabled, a static method on the WebView class.

Where can I find this class and will this be beneficial to do it in Worklight?

https://developers.google.com/chrome-developer-tools/docs/remote-debugging?hl=nl#debugging-webviews

Translocate answered 5/12, 2013 at 9:39 Comment(0)
V
13

Please note that WebView debugging is only relevant for Android 4.4 "KitKat" and not to any prior version of the Android OS.

To debug your Chromium WebView in a Worklight application with the Android environment,

  1. Open the Android SDK and update to API Level 19.
  • You will of course need either a device or emulator running this version.

  1. Make sure that in yourAppName\android\native\AndroidManifest.xml you add support for targetSdkVersion=19.

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

  1. Change the Build Target to Android 4.4:
  • Right-click on the generated Android project > Properties > Android > Build Target

  1. Open yourAppName\android\native\src\com\yourAppName\yourAppName.java and
  • Import the following:
import android.os.Build;
import android.util.Log;
import android.content.pm.ApplicationInfo;
import android.webkit.WebView;
  • Add the following to the onCreate() function:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
     if(0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)){
         WebView.setWebContentsDebuggingEnabled(true);
     }
}

The rest of the steps are as described in the Google documentation page.

I don't have an Android device to verify this, so please try.

As for whether it is beneficial or not, another debugging alternative can't hurt. It is up to you to decide if it's good or not, for you.

Vicarage answered 5/12, 2013 at 11:51 Comment(1)
This code is broken. Due to a typo, it unconditionally makes all WebView of the app debuggable (and thus accessible via USB Debugging) on Android KitKat and newer, regardless of whether the app is actually marked debuggable. The flag check is using = instead of &. It should be if(0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))Homelike

© 2022 - 2024 — McMap. All rights reserved.