Tag: android webview

Android WebView – JWT身份validation

我有一个Android应用程序,我正在从基本身份validation切换到JWT,所以,除了其他原因,我不必在本地存储用户的密码。 这对我所有的API请求都很有效,但我的应用程序的一部分使用WebView来显示托管在我的服务器上的自定义内容。 此内容还需要身份validation,目前我使用WebViewClient类中的用户名/密码组合来提供凭据。 现在我要去智威汤逊我不再有这些凭据,只有令牌。 有没有办法提供替代身份validation的WebViewClient ? 我的代码是Kotlin,但同样的原则适用于Java。 inner class WVClient : WebViewClient() { override fun onReceivedHttpAuthRequest(view: WebView, handler: HttpAuthHandler, host: String, realm: String) { // WHAT DO I DO HERE INSTEAD? handler.proceed(username, password) } }

url在三星设备中没有加载

我已经尝试了两个方法是“setWebViewClient”和“setWebChromeClient”,但URL仍然没有成功加载在一些设备,特别是在三星,搜索相关的配额,但没有find正确的答案,我可以使用直接意图的方法,但它不会打破冰,因为我想设置可见进度栏加载的url。 注意:整个代码在Kotlin中。 下面是我使用“setWebViewClient”时的代码: contactUsView!!.loadUrl(“https://www.google.co.in/”) contactUsView!!.visibility = View.GONE progress!!.visibility = View.VISIBLE contactUsView!!.setWebViewClient(object : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { System.out.println(“Progress_finished:::”) progress!!.visibility = View.GONE contactUsView!!.visibility = View.VISIBLE } }) 另一方面,我使用“setWebchromeclient”方法: contactUsView!!.loadUrl(“https://www.google.co.in/”) contactUsView!!.visibility = View.GONE progress!!.visibility = View.VISIBLE contactUsView!!.setWebChromeClient(object : WebChromeClient() { override fun onProgressChanged(view: WebView, newProgress: Int) { super.onProgressChanged(view, newProgress) System.out.println(“Progress1 :::”+ newProgress) if […]

EvaluateJavaScript只允许返回types的字符串?

我做了一个通用的函数(在Kotlin中),我可以根据给定的命令调用JavaScript函数。 fun evaluateJsFromNative(command: String, webView: WebView, function: (value : String) -> Unit ) { webView.evaluateJavascript(“(function() { return $command; })();”) { s -> function(s) } } 但是,它只允许将值String作为返回types。 如果我希望它是更通用的东西,我可以返回布尔types,诠释,甚至什么都没有,我怎么能使这更通用? 例如,我不能这样做…它会在function(s)声明需要是String fun evaluateJsFromNative(command: String, webView: WebView, function: (value : Boolean) -> Unit ) { webView.evaluateJavascript(“(function() { return $command; })();”) { s -> function(s) } }

如何在WebView Android中获取OnScroll位置

我尝试使用此代码在webview中获取当前位置 class ObservableWebView : WebView { private val TAG: String = ObservableWebView::class.java.simpleName constructor(context: Context?) : super(context) constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) { super.onScrollChanged(l, t, oldl, oldt) Log.d(TAG, "scroll1 " + l + " […]

在Webview中的window.reload

我试图让location.reload()在webView中工作。 但我无法加载一个网址。 我必须像这样加载它: web_view.loadData(filterString(editor.cleanText), "text/html", "UTF-8") 但是,然后js代码似乎无法重新显示webView。 filterString删除注释,因为它说“ Unexpected end of input ”,否则 我该如何做这项工作?

如何在WebView里添加“返回”功能在Fragment里面?

更新:解决! 问题与我的Viewpager而不是WebView有关。 我想添加一个“返回”功能,我的WebView里面的Fragment 。 但我不知道如何: public final class TestFragment extends Fragment { static WebView mWeb; private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.webview, null); mWeb = (WebView)mContentView.findViewById(R.id.webview); WebSettings settings = mWeb.getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(false); mWeb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mWeb.getSettings().setBuiltInZoomControls(false); mWeb.loadUrl("myurl…"); mWeb.setOnKeyListener(new OnKeyListener(){ public boolean onKey(View v, int keyCode, KeyEvent event) { […]

Android ProgessBar在加载WebView时

在我的应用程序中,我有一个从互联网上加载任何URL的WebView 。 现在,有时由于网络速度慢,页面加载需要很长时间,用户只能看到空白屏幕。 我想在WebView加载时显示一个ProgressBar ,当WebView完全加载时隐藏ProgessBar 。 我知道如何使用ProgressBar和AsyncTask ,但这是我的问题。 这是我用来加载我的WebView的代码。 mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new HelloWebViewClient()); mWebView.loadUrl(web_URL); 而这个我自定义的WebViewClient类 private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } 现在,如果我尝试使用AsyncTask显示ProgressBar那么我想我将不得不让代码加载我的AsyncTask的doInBackGround()函数中的URL,并通过onProgressUpdate()函数显示进度。 但是,如何在doInBackground()中加载URL,doInBackground()在非UI线程上运行,我不能在其中使用mWebView.loadUrl(web_URL) 。 有什么建议么? 我错过了什么明显的? 请指导我

Kotlin webview崩溃

我想从一个Fragment访问一个WebView和kotlin不停地说: kotlin.TypeCastException: null cannot be cast to non-null type android.webkit.WebView 我试图使其为默认,然后初始化它,但也不起作用。 任何建议,我怎样才能使其工作? 我的代码: private lateinit var webView: WebView override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater!!.inflate(R.layout.editor_edit_fragment, container, false) webView = view.findViewById(R.id.webview) as WebView resumeWebView() return view } XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webview" […]