android.webkit.WebView.post()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中android.webkit.WebView.post()方法的一些代码示例,展示了WebView.post()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.post()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:post

WebView.post介绍

暂无

代码示例

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

public void initProxyWebView() {
  if (getActivity() != null && SysApplication.isInitProxy && !isSetProxy) {
    webView.post(new Runnable() {
      @Override
      public void run() {
        if(ProxyUtils.setProxy(webView, "127.0.0.1", SysApplication.proxyPort)){
          Log.e("~~~~", "initProxyWebView()");
          webView.loadUrl(urlText.getText() + "");
          isSetProxy = true;
        }else{
          Toast.makeText(webView.getContext(),"Set proxy fail!",Toast.LENGTH_LONG).show();
        }
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

final Bitmap b = Bitmap.createBitmap(containerWidth, containerHeight, Bitmap.Config.ARGB_8888);
final AtomicBoolean ready = new AtomicBoolean(false); 
w.post(new Runnable() {

代码示例来源:origin: kot32go/KSimpleLibrary

@Override
public View onRefresh() {
  //webview 需要在主线程刷新
  webView.post(new Runnable() {
    @Override
    public void run() {
      webView.reload();
    }
  });
  //刷新啦
  return null;
}

代码示例来源:origin: adjust/android_sdk

public static void execSingleValueCallback(final WebView webView, final String commandName, final String value) {
  if (webView == null) {
    return;
  }
  webView.post(new Runnable() {
    @Override
    public void run() {
      String command = "javascript:" + commandName + "('" + value + "');";
      webView.loadUrl(command);
    }
  });
}

代码示例来源:origin: adjust/android_sdk

public static void sendDeeplinkToWebView(final WebView webView, final Uri deeplink) {
  // If web view is initialised, trigger adjust_deeplink method which user should override.
  // In this method, the content of the deeplink will be delivered.
  if (webView != null) {
    webView.post(new Runnable() {
      @Override
      public void run() {
        String command = "javascript:adjust_deeplink('" + deeplink.toString() + "');";
        webView.loadUrl(command);
      }
    });
  }
}

代码示例来源:origin: bertrandmartel/youtubetv

/**
 * Call javascript functions in webview thread.
 *
 * @param webView    webview object
 * @param methodName function name
 * @param params     function parameters
 */
public static void callOnWebviewThread(final WebView webView, final String methodName, final Object... params) {
  webView.post(new Runnable() {
    @Override
    public void run() {
      WebviewUtils.callJavaScript(webView, methodName, params);
    }
  });
}

代码示例来源:origin: adjust/android_sdk

public static void execEventSuccessCallbackCommand(final WebView webView, final String commandName, final AdjustEventSuccess eventSuccess) {
  if (webView == null) {
    return;
  }
  webView.post(new Runnable() {
    @Override
    public void run() {
      JSONObject jsonEventSuccess = new JSONObject();
      try {
        jsonEventSuccess.put("eventToken", eventSuccess.eventToken == null ? JSONObject.NULL : eventSuccess.eventToken);
        jsonEventSuccess.put("message", eventSuccess.message == null ? JSONObject.NULL : eventSuccess.message);
        jsonEventSuccess.put("adid", eventSuccess.adid == null ? JSONObject.NULL : eventSuccess.adid);
        jsonEventSuccess.put("timestamp", eventSuccess.timestamp == null ? JSONObject.NULL : eventSuccess.timestamp);
        jsonEventSuccess.put("callbackId", eventSuccess.callbackId == null ? JSONObject.NULL : eventSuccess.callbackId);
        jsonEventSuccess.put("jsonResponse", eventSuccess.jsonResponse == null ? JSONObject.NULL : eventSuccess.jsonResponse);
        String command = "javascript:" + commandName + "(" + jsonEventSuccess.toString() + ");";
        webView.loadUrl(command);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  });
}

代码示例来源:origin: adjust/android_sdk

public static void execEventFailureCallbackCommand(final WebView webView, final String commandName, final AdjustEventFailure eventFailure) {
  if (webView == null) {
    return;
  }
  webView.post(new Runnable() {
    @Override
    public void run() {
      JSONObject jsonEventFailure = new JSONObject();
      try {
        jsonEventFailure.put("eventToken", eventFailure.eventToken == null ? JSONObject.NULL : eventFailure.eventToken);
        jsonEventFailure.put("message", eventFailure.message == null ? JSONObject.NULL : eventFailure.message);
        jsonEventFailure.put("adid", eventFailure.adid == null ? JSONObject.NULL : eventFailure.adid);
        jsonEventFailure.put("timestamp", eventFailure.timestamp == null ? JSONObject.NULL : eventFailure.timestamp);
        jsonEventFailure.put("willRetry", eventFailure.willRetry ? String.valueOf(true) : String.valueOf(false));
        jsonEventFailure.put("callbackId", eventFailure.callbackId == null ? JSONObject.NULL : eventFailure.callbackId);
        jsonEventFailure.put("jsonResponse", eventFailure.jsonResponse == null ? JSONObject.NULL : eventFailure.jsonResponse);
        String command = "javascript:" + commandName + "(" + jsonEventFailure.toString() + ");";
        webView.loadUrl(command);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  });
}

代码示例来源:origin: adjust/android_sdk

public static void execSessionSuccessCallbackCommand(final WebView webView, final String commandName, final AdjustSessionSuccess sessionSuccess) {
  if (webView == null) {
    return;
  }
  webView.post(new Runnable() {
    @Override
    public void run() {
      JSONObject jsonSessionSuccess = new JSONObject();
      try {
        jsonSessionSuccess.put("message", sessionSuccess.message == null ? JSONObject.NULL : sessionSuccess.message);
        jsonSessionSuccess.put("adid", sessionSuccess.adid == null ? JSONObject.NULL : sessionSuccess.adid);
        jsonSessionSuccess.put("timestamp", sessionSuccess.timestamp == null ? JSONObject.NULL : sessionSuccess.timestamp);
        jsonSessionSuccess.put("jsonResponse", sessionSuccess.jsonResponse == null ? JSONObject.NULL : sessionSuccess.jsonResponse);
        String command = "javascript:" + commandName + "(" + jsonSessionSuccess.toString() + ");";
        webView.loadUrl(command);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
  });
}

代码示例来源:origin: AnyChart/AnyChart-Android

@Override
  public void onJsLineAdd(final String jsLine) {
    webView.post(new Runnable() {
      @Override
      public void run() {
        if (isRestored) {
          return;
        }
        if (isRendered) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.evaluateJavascript(jsLine, null);
          } else {
            webView.loadUrl("javascript:" + jsLine);
          }
        } else {
          js.append(jsLine);
        }
      }
    });
  }
});

代码示例来源:origin: skjolber/external-nfc-api

private void call(final String url) {
  Log.d(TAG, url);
  
   webView.post(new Runnable() {
    @Override
    public void run() { 
      webView.loadUrl(url);
    }
  }); 
   }

代码示例来源:origin: zhangke3016/GeneratePicture

/**
 * 生成图片分享按钮
 * @param v
 */
public void ClickOnSelect(View v){
  webView.post(new Runnable() {
    @Override
    public void run() {
      WebViewHelper.getInstance().getSelectedData(webView);
    }
  });
  btn_getData.setVisibility(View.GONE);
}

代码示例来源:origin: matrix-org/matrix-android-sdk

@Override
  public void run() {
    mWebView.loadUrl("javascript:initWithInvite('" + aCallId + "'," + aCallInviteParams.toString() + ")");
    mIsIncomingPrepared = true;
    mWebView.post(new Runnable() {
      @Override
      public void run() {
        checkPendingCandidates();
      }
    });
  }
});

代码示例来源:origin: matrix-org/matrix-android-sdk

@Override
  public void run() {
    mWebView.loadUrl("javascript:onHangupReceived(" + event.getContent().toString() + ")");
    mWebView.post(new Runnable() {
      @Override
      public void run() {
        dispatchOnCallEnd(END_CALL_REASON_PEER_HANG_UP);
      }
    });
  }
});

代码示例来源:origin: liuzho/ONE

@JavascriptInterface
  public void textContent(final String html) {
    mWvContent.post(new Runnable() {
      @Override
      public void run() {
        mWvContent.loadDataWithBaseURL("about:blank",
            HtmlFmtUtil.fmt(html), "text/html", "utf-8", null);
        hiddenLoadingView();
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

@Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   view.post(new Runnable() {
     @Override
     public void run() {
       view.loadUrl(url, getExtraHeaders());
     }
   });
   // true means: yes, we are overriding the loading of this url
   return true;
 }

代码示例来源:origin: matrix-org/matrix-android-sdk

/**
 * A new Ice candidate is received
 *
 * @param candidates the ice candidates
 */
public void onNewCandidates(final JsonElement candidates) {
  if (!CALL_STATE_CREATED.equals(getCallState()) && (null != mWebView)) {
    mWebView.post(new Runnable() {
      @Override
      public void run() {
        mWebView.loadUrl("javascript:gotRemoteCandidates(" + candidates.toString() + ")");
      }
    });
  }
}

代码示例来源:origin: open-android/BridgeWebView

/**
 * 统一管理所有android调用js方法
 *
 * @param callback js回调方法名
 * @param json     传递json数据
 */
private void invokeJavaScript(final String callback, final String json) {
  showToast("回调js方法:"+callback+", 参数:"+json);
  if(TextUtils.isEmpty(callback)) return;
  //调用js方法必须在主线程
  webView.post(new Runnable() {
    @Override
    public void run() {
      webView.loadUrl("javascript:" + callback + "(" + json + ")");
    }
  });
}

代码示例来源:origin: WhiteDG/BihuDaily

@JavascriptInterface
public void loadImage(final String imgPath) {
  if (TextUtils.isEmpty(imgPath))
    return;
  webContent.post(new Runnable() {
    @Override
    public void run() {
      Glide.with(BaseDetailActivity.this).load(imgPath)
          .downloadOnly(new SimpleTarget<File>() {
            @Override
            public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
              String str = "file://" + resource.getAbsolutePath();//加载完成的图片地址
              try {
                String[] arrayOfString = new String[2];
                arrayOfString[0] = URLEncoder.encode(imgPath,"UTF-8");//旧url
                arrayOfString[1] = str;
                onImageLoadingComplete("onImageLoadingComplete", arrayOfString);
              } catch (Exception e) {
              }
            }
          });
    }
  });
}

代码示例来源:origin: free46000/HybridFoundation

private static void execJs(WebView webView, String jsCode) {
  if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
    webView.post(() -> execJs(webView, jsCode));
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    webView.evaluateJavascript(jsCode, null);
  } else {
    webView.loadUrl(jsCode);
  }
}

相关文章

WebView类方法