using getWebViewLooper API for Android 28+

This commit is contained in:
Lorenzo Pichilli 2022-04-18 23:57:11 +02:00
parent 2eb31ee74f
commit 254ba1a1b8
5 changed files with 19 additions and 5 deletions

View File

@ -35,7 +35,7 @@ public class JavaScriptBridgeInterface {
return;
}
final Handler handler = new Handler(Looper.getMainLooper());
final Handler handler = new Handler(inAppWebView.getWebViewLooper());
handler.post(new Runnable() {
@Override
public void run() {
@ -58,7 +58,7 @@ public class JavaScriptBridgeInterface {
// java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread.
// https://github.com/pichillilorenzo/flutter_inappwebview/issues/98
final Handler handler = new Handler(Looper.getMainLooper());
final Handler handler = new Handler(inAppWebView.getWebViewLooper());
handler.post(new Runnable() {
@Override
public void run() {

View File

@ -97,7 +97,7 @@ public class ContentBlockerHandler {
final String[] webViewUrl = new String[1];
if (!trigger.getLoadType().isEmpty() || !trigger.getIfTopUrl().isEmpty() || !trigger.getUnlessTopUrl().isEmpty()) {
final CountDownLatch latch = new CountDownLatch(1);
Handler handler = new Handler(Looper.getMainLooper());
Handler handler = new Handler(webView.getWebViewLooper());
handler.post(new Runnable() {
@Override
public void run() {
@ -160,7 +160,7 @@ public class ContentBlockerHandler {
" d.addEventListener('DOMContentLoaded', function(event) { hide(); }); " +
"})(document);";
final Handler handler = new Handler(Looper.getMainLooper());
final Handler handler = new Handler(webView.getWebViewLooper());
handler.post(new Runnable() {
@Override
public void run() {

View File

@ -133,7 +133,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
public LinearLayout floatingContextMenu = null;
@Nullable
public Map<String, Object> contextMenu = null;
public Handler mainLooperHandler = new Handler(Looper.getMainLooper());
public Handler mainLooperHandler = new Handler(getWebViewLooper());
static Handler mHandler = new Handler();
public Runnable checkScrollStoppedTask;
@ -1672,6 +1672,14 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
webMessageListeners.clear();
}
@Override
public Looper getWebViewLooper() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return super.getWebViewLooper();
}
return Looper.getMainLooper();
}
@Override
public void postWebMessage(com.pichillilorenzo.flutter_inappwebview.types.WebMessage message, Uri targetOrigin, ValueCallback<String> callback) throws Exception {
throw new UnsupportedOperationException();

View File

@ -3,6 +3,7 @@ package com.pichillilorenzo.flutter_inappwebview.types;
import android.content.Context;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.os.Looper;
import android.webkit.ValueCallback;
import android.webkit.WebMessage;
import android.webkit.WebView;
@ -98,4 +99,5 @@ public interface InAppWebViewInterface {
void setWebMessageChannels(Map<String, WebMessageChannel> webMessageChannels);
void disposeWebMessageChannels();
void disposeWebMessageListeners();
Looper getWebViewLooper();
}

View File

@ -5271,6 +5271,10 @@ setTimeout(function() {
expect(await AndroidInAppWebViewController.getCurrentWebViewPackage(),
isNotNull);
}, skip: !Platform.isAndroid);
test('setWebContentsDebuggingEnabled', () async {
expect(AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true), completes);
}, skip: !Platform.isAndroid);
}, skip: !Platform.isAndroid);
group('ios methods', () {