You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/01/18 17:47:48 UTC

[GitHub] caiocsl commented on issue #386: Error on Android 6 and 7 using plugin from master

caiocsl commented on issue #386: Error on Android 6 and 7 using plugin from master
URL: https://github.com/apache/cordova-plugin-inappbrowser/issues/386#issuecomment-455630801
 
 
   The problem begins at line 261:
   
   ```
   this.cordova.getActivity().runOnUiThread(new Runnable() {
   
               @SuppressLint("NewApi")
               @Override
               public void run() {
                   ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
                   inAppWebView.loadUrl(url);
               }
           });
   ```
   
   **inAppWebView.getWebViewClient()** throws the error because the method **getWebViewClient()** was added in API level 26 (Android 7.1) as you can see in the [Android Developers documentation](https://developer.android.com/reference/android/webkit/WebView.html#getWebViewClient())
   
   So, the workaround I've came up with, is to actually make an API if:
   
   ```
   this.cordova.getActivity().runOnUiThread(new Runnable() {
           @SuppressLint("NewApi")
           @Override
           public void run() {
   
                   if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.N_MR1) {
                       currentClient.waitForBeforeload = false;
   		    inAppWebView.setWebViewClient(currentClient);
                   } else {
                       ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
                   }	
   
                   inAppWebView.loadUrl(url);
           }
       });
   ```
   
   Now, this is the main change, but the **currentClient** does not exist, so i've had to create this class property:
   
   `private InAppBrowserClient currentClient;`
   
   
   And on line 951, where we have this local object assign:
   
   ```
   WebViewClient client = new InAppBrowserClient(thatWebView, edittext, beforeload);
   inAppWebView.setWebViewClient(client);
   ```
   
   I've changed it to this:
   
   ```
   currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload);
   inAppWebView.setWebViewClient(currentClient);
   ```
   
   
   Now what happens is, if you're on Android 7.1 or higher, nothing changes.
   
   But now, on Android 7 or lower, when the code needs to change the **waitForBeforeload** value of the **InAppBrowserClient** in use by the webview, you have access to that on the class scope, instead of the local only as it was before.
   
   It works for me =)
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org