本文整理汇总了Java中android.webkit.WebView.evaluateJavascript方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.evaluateJavascript方法的具体用法?Java WebView.evaluateJavascript怎么用?Java WebView.evaluateJavascript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.evaluateJavascript方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPageFinished
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public void onPageFinished(WebView view, String url) {
if (view.isShown()) {
mBrowserController.updateUrl(url, true);
view.postInvalidate();
}
if (view.getTitle() == null || view.getTitle().isEmpty()) {
mTitle.setTitle(mActivity.getString(R.string.untitled));
} else {
mTitle.setTitle(view.getTitle());
}
if (API >= android.os.Build.VERSION_CODES.KITKAT && mInvertPage) {
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
}
mBrowserController.update();
}
示例2: onPageFinished
import android.webkit.WebView; //导入方法依赖的package包/类
@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);
}
}
示例3: myEvaluateJavaScript
import android.webkit.WebView; //导入方法依赖的package包/类
private void myEvaluateJavaScript(WebView webView, String script) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(script, null);
} else {
webView.loadUrl("javascript:" + script);
}
}
示例4: stopAndStartVideos
import android.webkit.WebView; //导入方法依赖的package包/类
private void stopAndStartVideos(WebView oldView, WebView currentView){
// Selects the first (and presumably only) video on the page if any exists
String videoSelector = "document.getElementsByTagName('video')[0]";
if(oldView != null)
oldView.evaluateJavascript(videoSelector + ".pause();", null);
if(currentView != null)
currentView.evaluateJavascript(videoSelector + ".play();", null);
}
示例5: invoke
import android.webkit.WebView; //导入方法依赖的package包/类
public void invoke(WebView webView, ValueCallback<String> callback) {
if (webView == null)
return;
if (!mJsFuncSign.startsWith(JS_FUNC_PREFIX)) {
mJsFuncSign = JS_FUNC_PREFIX + mJsFuncSign;
}
// api 19
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && callback != null) {
webView.evaluateJavascript(mJsFuncSign, callback);
} else {
webView.loadUrl(mJsFuncSign);
}
}
示例6: onPageFinished
import android.webkit.WebView; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onPageFinished(@NonNull WebView view, String url) {
if (view.isShown()) {
mUIController.updateUrl(url, false);
mUIController.setBackButtonEnabled(view.canGoBack());
mUIController.setForwardButtonEnabled(view.canGoForward());
view.postInvalidate();
}
if (view.getTitle() == null || view.getTitle().isEmpty()) {
mLightningView.getTitleInfo().setTitle(mActivity.getString(R.string.untitled));
} else {
mLightningView.getTitleInfo().setTitle(view.getTitle());
}
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT &&
mLightningView.getInvertePage()) {
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
}
mUIController.tabChanged(mLightningView);
}
示例7: inject
import android.webkit.WebView; //导入方法依赖的package包/类
private void inject(WebView view, String script, ValueCallback<String> callback) {
view.evaluateJavascript(script, callback);
}
示例8: injection
import android.webkit.WebView; //导入方法依赖的package包/类
private void injection(WebView webView) {
// Log.d("TTT_d", "injection - " + currVideoId);
if (TextUtils.isEmpty(currVideoId) == true) {
return;
}
if (Build.VERSION.SDK_INT >= 19) {
webView.evaluateJavascript(rawJS, null);
} else {
webView.loadUrl("javascript:" + rawJS);
}
}
示例9: evalJS
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* Evaluates JavaScript code in an API-level independent way.
*
* Note: all WebView methods must be called from the UIThread.
*/
@UiThread
static void evalJS(final WebView webView, final String script) {
// implementation via http://stackoverflow.com/a/30828985/
if (Build.VERSION.SDK_INT >= 19) {
webView.evaluateJavascript(script, null);
} else {
webView.loadUrl("javascript:" + script);
}
}
示例10: initWebView
import android.webkit.WebView; //导入方法依赖的package包/类
private void initWebView() {
wvWeb = (WebView) findViewById(R.id.wv_web);
wvWeb.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
fl.setVisibility(View.GONE);
url = wvWeb.getUrl();
} else {
fl.setVisibility(View.VISIBLE);
}
}
});
wvWeb.setWebViewClient(new WebViewClient());
wvWeb.getSettings().setBuiltInZoomControls(false);
wvWeb.getSettings().setJavaScriptEnabled(true);
wvWeb.getSettings().setDomStorageEnabled(true);
wvWeb.getSettings().setDatabaseEnabled(true);
// wvWeb.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
wvWeb.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); //设置 缓存模式
String cacheDirPath = getFilesDir().getAbsolutePath();
// String cacheDirPath = getCacheDir().getAbsolutePath()+Constant.APP_DB_DIRNAME;
//设置数据库缓存路径
wvWeb.getSettings().setDatabasePath(cacheDirPath);
//设置 Application Caches 缓存目录
wvWeb.getSettings().setAppCachePath(cacheDirPath);
wvWeb.getSettings().setAppCacheEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
Log.i("log", "initWebView: -------------- 1");
wvWeb.evaluateJavascript("document.body.style.backgroundColor=\"black\";document.body.style.color=\"white\";", null);
} else {
Log.i("log", "initWebView: -------------- 2");
wvWeb.loadUrl("javascript:document.body.style.backgroundColor=\"#black\";document.body.style.color=\"white\";");
}
wvWeb.loadUrl(url);
}