public void linkBridge() { if (messagingEnabled) { if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // See isNative in lodash String testPostMessageNative = "String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage')"; evaluateJavascript(testPostMessageNative, new ValueCallback<String>() { @Override public void onReceiveValue(String value) { if (value.equals("true")) { FLog.w(ReactConstants.TAG, "Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined"); } } }); } loadUrl("javascript:(" + "window.originalPostMessage = window.postMessage," + "window.postMessage = function(data) {" + BRIDGE_NAME + ".postMessage(String(data));" + "}" + ")"); } }
private void openFileChooserImplForAndroid5(ValueCallback<Uri[]> uploadMsg) { mUploadMessageForAndroid5 = uploadMsg; Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "图片选择"); mActivity.startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE_FOR_ANDROID_5); }
@TargetApi(Build.VERSION_CODES.KITKAT) @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (url.contains("login/")) { UserModel model = new UserModel().find().executeSingle(); if (model != null) { webView.evaluateJavascript("(function() {document.getElementsByName('username')[0].value='" + model.username + "';document.getElementsByName('password')[0].value='" + model.password + "';document.getElementById('login').submit(); " + "return { var1: \"variable1\", var2: \"variable2\" }; })();", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { Log.d("authentication", "success"); } }); } } }
private boolean openFileChooserAboveL(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { LogUtils.i(TAG, "fileChooserParams:" + fileChooserParams.getAcceptTypes() + " getTitle:" + fileChooserParams.getTitle() + " accept:" + Arrays.toString(fileChooserParams.getAcceptTypes()) + " length:" + fileChooserParams.getAcceptTypes().length + " :" + fileChooserParams.isCaptureEnabled() + " " + fileChooserParams.getFilenameHint() + " intent:" + fileChooserParams.createIntent().toString()+" mode:"+fileChooserParams.getMode()); Activity mActivity = this.mActivityWeakReference.get(); if (mActivity == null || mActivity.isFinishing()) { filePathCallback.onReceiveValue(new Uri[]{}); return false; } IFileUploadChooser mIFileUploadChooser = this.mIFileUploadChooser; this.mIFileUploadChooser = mIFileUploadChooser = new FileUpLoadChooserImpl.Builder() .setWebView(webView) .setActivity(mActivity) .setUriValueCallbacks(filePathCallback) .setFileChooserParams(fileChooserParams) .setFileUploadMsgConfig(mChromeClientMsgCfg.getFileUploadMsgConfig()) .setPermissionInterceptor(this.mPermissionInterceptor) .build(); mIFileUploadChooser.openFileChooser(); return true; }
/** * 调用js串的时候 引用此方法 例:document.querySelectorAll('*[name=description]')[0].getAttribute('content') * * @param funtionName * 需要传递的JS串 */ protected String callJsDescription(final String funtionName) { runOnUiThread(new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webView.evaluateJavascript(funtionName, new ValueCallback<String>() { @Override public void onReceiveValue(String value) { Log.e("value", value); content = value; } }); } else { webView.loadUrl(funtionName); } } }); return content; }
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); final String password = profile.getString("password", null); final String username = profile.getString("username", null); if(profile.getString("username",null).equals("default") || profile.getString("password",null).equals("default")) { Toast.makeText(getApplicationContext(),"Enter your login details properly !",Toast.LENGTH_LONG).show(); Intent log = new Intent(Moodle.this,LoginActivity.class); startActivity(log); return; } final String js = "javascript:" + "document.getElementById('password').value = '" + password + "';" + "document.getElementById('username').value = '" + username + "';" + "document.getElementById('loginbtn').click()"; if (Build.VERSION.SDK_INT >= 19) { view.evaluateJavascript(js, new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }); } else { view.loadUrl(js); } }
@Override public void evaluateJavascript(String js, ValueCallback<String> callback) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { webView.evaluateJavascript(js, callback); } else { LOG.d(TAG, "This webview is using the old bridge"); } }
public void openFileChooser(ValueCallback<Uri> uploadMsg) { BrowserActivity.this.mUploadMessage = uploadMsg; Intent i = new Intent("android.intent.action.GET_CONTENT"); i.addCategory("android.intent.category.OPENABLE"); i.setType("image/*"); BrowserActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), 1); }
public AnnouncementsScraper(Blackboard blackboard) { super(blackboard); handler = new Handler(); runnable = new Runnable() { @Override public void run() { if (!isCancelled()) { getBlackboard().getHtmlContent("announcementList", new ValueCallback<String>() { @Override public void onReceiveValue(String s) { JsonReader reader = new JsonReader(new StringReader(s)); reader.setLenient(true); try { if (reader.peek() != JsonToken.NULL) { if (reader.peek() == JsonToken.STRING) onComplete(reader.nextString()); } } catch (Exception ignored) { } try { reader.close(); } catch (IOException ignored) { } if (!isComplete()) { onError(false); handler.postDelayed(runnable, 1000); } } }); } } }; }
@Override public void onPageFinished(WebView view, String url) { mWebView = view; setUpWebView(view); while (!mToInjectJavaScripts.isEmpty()) { Pair<String, ValueCallback<String>> pair = mToInjectJavaScripts.poll(); inject(view, pair.first, pair.second); } super.onPageFinished(view, url); }
public void openFileChooser(ValueCallback<Uri> uploadMsg) { BetBrowserFragment.this.mUploadMessage = uploadMsg; Intent i = new Intent("android.intent.action.GET_CONTENT"); i.addCategory("android.intent.category.OPENABLE"); i.setType("image/*"); BetBrowserFragment.this.startActivityForResult(Intent.createChooser(i, "File " + "Chooser"), 1); }
private void openFileChooserImpl(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); mActivity.startActivityForResult(Intent.createChooser(i, "文件选择"), FILECHOOSER_RESULTCODE); }
/** * Sets an attribute of an element in the WebView * @param id the element to apply the attribute to * @param attribute the name of the attribute to change * @param value the value to change the attribute to */ public void setAttribute(String id, String attribute, String value) { webView.evaluateJavascript("(function(){document.getElementById('" + id + "')." + attribute + " = " + value + ";})();", new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }); }
private void clearCookiesAsync(final Callback callback) { getCookieManager().removeAllCookies( new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { mCookieSaver.onCookiesModified(); callback.invoke(value); } }); }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public void onClick(View v) { switch (v.getId()){ case R.id.callJsNoParamsButton: mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroid"); break; case R.id.callJsOneParamsButton: mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroidParam","Hello ! Agentweb"); break; case R.id.callJsMoreParamsButton: mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroidMoreParams", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { Log.i("Info","value:"+value); } },getJson(),"say:", " Hello! Agentweb"); break; case R.id.jsJavaCommunicationButton: mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroidInteraction","你好Js"); break; } }
@Override public void callJs(String js, final ValueCallback<String> callback) { LogUtils.i(TAG,"method callJs:"+js); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { this.evaluateJs(js, callback); } else { this.loadJs(js); } }
public UsernameScraper(Blackboard blackboard) { super(blackboard); handler = new Handler(); runnable = new Runnable() { @Override public void run() { if (!isCancelled()) { getBlackboard().getAttribute("global-nav-link", "innerText", new ValueCallback<String>() { @Override public void onReceiveValue(String s) { JsonReader reader = new JsonReader(new StringReader(s)); reader.setLenient(true); try { if (reader.peek() != JsonToken.NULL) { if (reader.peek() == JsonToken.STRING) onComplete(reader.nextString().replace("[0-9]", "")); } } catch (Exception ignored) { } try { reader.close(); } catch (IOException ignored) { } if (!isComplete()) { onError(false); handler.postDelayed(runnable, 1000); } } }); } } }; }
@Override public void quickCallJs(String method, ValueCallback<String> callback,String... params) { StringBuilder sb=new StringBuilder(); sb.append("javascript:"+method); if(params==null||params.length==0){ sb.append("()"); }else{ sb.append("(").append(concat(params)).append(")"); } callJs(sb.toString(),callback); }
/** * opens a file chooser * param ValueCallback is the message from the WebView indicating a file chooser * should be opened */ @Override public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { LogUtils.i(TAG, "openFileChooser>=5.0"); if (AgentWebUtils.isOverriedMethod(mWebChromeClient, "onShowFileChooser", ChromePath + ".onShowFileChooser", WebView.class, ValueCallback.class, FileChooserParams.class)) { return super.onShowFileChooser(webView, filePathCallback, fileChooserParams); } return openFileChooserAboveL(webView, filePathCallback, fileChooserParams); }
private static ValueCallback<Boolean> getDefaultIgnoreCallback() { return new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean ignore) { Log.i("removeExpiredCookies:" + ignore); } }; }
public void openFileChooser(ValueCallback valueCallback, String acceptType) { Log.i(TAG, "openFileChooser>3.0"); if (AgentWebUtils.isOverriedMethod(mWebChromeClient, "openFileChooser", ChromePath + ".openFileChooser", ValueCallback.class, String.class)) { super.openFileChooser(valueCallback, acceptType); return; } createAndOpenCommonFileLoader(valueCallback, acceptType); }
public Builder setUriValueCallback(ValueCallback<Uri> uriValueCallback) { mUriValueCallback = uriValueCallback; isL = false; jsChannel = false; mUriValueCallbacks = null; mJsChannelCallback = null; return this; }
public Builder setUriValueCallbacks(ValueCallback<Uri[]> uriValueCallbacks) { mUriValueCallbacks = uriValueCallbacks; isL = true; mUriValueCallback = null; mJsChannelCallback = null; jsChannel = false; return this; }
@Override public void callJs(String params, final ValueCallback<String> callback) { if (Thread.currentThread() != Looper.getMainLooper().getThread()) { callSafeCallJs(params, callback); return; } super.callJs(params,callback); }
private void evaluateJs(String js, final ValueCallback<String>callback){ mWebView.evaluateJavascript(js, new com.tencent.smtt.sdk.ValueCallback<String>() { @Override public void onReceiveValue(String value) { if (callback != null) callback.onReceiveValue(value); } }); }
public void runJSonPage(String url) { Log.d("ficsaveM/runJSCalled", url + " " + ficUrl); // Check if not loading the download URL and some fanfic url is there to download if (!url.contains(getString(R.string.ficsave_download_url))) { if (!ficUrl.isEmpty() && !Patterns.WEB_URL.matcher(ficUrl).matches()) { Toast.makeText( getApplicationContext(), R.string.invalid_fic_url + " " + ficUrl, Toast.LENGTH_LONG ).show(); } // Get javascript to run on page final String jsString = getJsScript(); // Execute Javascript on a new thread 2 second after page load Log.d("ficsaveM/JSrun", "Start"); new Handler().postDelayed(new Runnable() { @Override public void run() { mWebview.evaluateJavascript(jsString, new ValueCallback<String>() { @Override public void onReceiveValue(String value) { Log.d("ficsaveM/JSrun", "Success, Value: " + value); trackJsRunSuccess(value); // empty the fanfic url so it won't get downloaded again somehow ficUrl = ""; } }); } }, 2000); } }
@Override /** * opens a file chooser * param ValueCallback is the message from the WebView indicating a file chooser * should be opened */ public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1); }
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { BetBrowserFragment.this.mUploadMessage = uploadMsg; Intent i = new Intent("android.intent.action.GET_CONTENT"); i.addCategory("android.intent.category.OPENABLE"); i.setType("image/*"); BetBrowserFragment.this.startActivityForResult(Intent.createChooser(i, "File " + "Chooser"), 1); }
/** * 执行网页中的js方法 */ void callJsFunction() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mWebView.evaluateJavascript("javascript:callJS()", new ValueCallback<String>() { @Override public void onReceiveValue(String value) { //接受返回值 } }); } else { mWebView.loadUrl("javascript:callJS()"); } }
@Override public void showFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { setFilePathCallbacks(filePathCallback); String[] acceptTypes = new String[0]; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { acceptTypes = fileChooserParams.getAcceptTypes(); } dealOpenFileChooser(acceptTypes.length > 0 ? acceptTypes[0] : ""); }
@Override public void evaluateJavascript(String js, ValueCallback<String> callback) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // For override to type casting by Jeremy webView.evaluateJavascript(js, (com.tencent.smtt.sdk.ValueCallback) callback); } else { LOG.d(TAG, "This webview is using the old bridge"); } }
@Override public boolean openFileChooser(ValueCallback<Uri> callback, String[] acceptType) { if (super.openFileChooser(callback, acceptType)) { return true; } new FileChooserDialogBuilder(getContext()) .title(R.string.text_select_file_to_upload) .dir(StorageFileProvider.DEFAULT_DIRECTORY_PATH) .singleChoice(file -> callback.onReceiveValue(Uri.fromFile(file))) .cancelListener(dialog -> callback.onReceiveValue(null)) .show(); return true; }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { openFileChooser(value -> { if (value == null) { filePathCallback.onReceiveValue(null); } else { filePathCallback.onReceiveValue(new Uri[]{value}); } }, fileChooserParams.getAcceptTypes()); return true; }