Webview 内容未加载所有设备 [英] Webview content not loading all devices

查看:57
本文介绍了Webview 内容未加载所有设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webview 将数据从服务器加载到设备.但它不会在像 Moto x 这样的少数设备中加载,并且在某些设备中加载但是当从 webview 页面转到另一个页面并返回到同一页面时,webview 内容丢失了.这发生在 Xperia z 中.其他设备三星,小米一切正常.

I am loading data from server to device using webview. but its not loading in few device like Moto x and In some device loading but when go to another page from webview page and back to same page then webview content lost.this happening in Xperia z.Other devices samsung,Xiomi everthing working fine.

问题是什么以及如何解决这个问题,以便 webview 数据呈现所有设备.

what is the problem and how can solve this problem so webview data render all device fine.

LOGCAT -:

[AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:145] Constructor called with outAttrs:  inputType=0xa1 imeOptions=0x12000000 privateImeOptions=null
 D/cr_Ime: actionLabel=null actionId=0
 D/cr_Ime: initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0
 D/cr_Ime: hintText=null label=null
 D/cr_Ime: packageName=com.org.AmarUjala.news fieldId=-1 fieldName=null
 D/cr_Ime: extras=null
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
 D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText

这里是Xml代码

          <WebView
            android:id="@+id/storyText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:lineSpacingExtra="3dp"
            android:scrollbars="none"
            android:visibility="gone"
            android:textColor="@color/black" /> 

Java 代码如下:

int currentApi = android.os.Build.VERSION.SDK_INT;
mWebView.setInitialScale(0);
mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.requestFocusFromTouch();
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setLoadsImagesAutomatically(true);
settings.setSupportZoom(false);
settings.setAppCacheEnabled(false);
settings.setSavePassword(false);
settings.setPluginState(WebSettings.PluginState.ON);
settings.setLoadsImagesAutomatically(true);
settings.setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadDataWithBaseURL("", ftext,"text/html",utf-8,"");              
mWebView.setVisibility(View.VISIBLE);

推荐答案

有些配置没有区别,也许你可以删除它们:

There are some configurations that make no difference and perhaps you could remove them:

mWebView.setInitialScale(0); // This is 0 by default scale

settings.setAppCacheEnabled(false); // This is false by default

settings.setLoadsImagesAutomatically(true); //This is twice
settings.setLoadsImagesAutomatically(true); //This is twice

settings.setPluginState(WebSettings.PluginState.ON); // This is deprecated since API level 18

如果那些给您带来麻烦的设备在 API 级别 18+ 上运行,则上述行可能是问题所在.

If those devices giving you trouble are running on API level 18+ the above line might be the issue.

那么,尽管您起诉了这种方法,但您似乎并未从 URL 加载内容:

Then it doesn't seem you are loading the content from a URL despite you are suing this method:

mWebView.loadDataWithBaseURL("", ftext,"text/html",utf-8,""); //The first parameter is empty and could lead to 'about:blank'

如果您从远程服务器加载并有一个 url,请使用 loadDataWithBaseURL,否则如果您从本地加载,则使用其他方法,例如:webview.loadData(summary, "text/html", null);

Use loadDataWithBaseURL if you are loading from a remote server and have a url, otherwise if you are loading from local then use other methods like: webview.loadData(summary, "text/html", null);

然后根据您的最新评论,我会将用户浏览的 Url 保存在一个集合中,甚至将 scrollY 保存在这些特定设备中.然后听后退"按钮并浏览这些设备中的保存网址,如果需要,在每个页面上重新加载页面.

Then based on your latest comments, I would save the Urls that the user navigates through in a collection and even save the scrollY in those specific devices. Then listen to the Back button and navigate through the save urls in those devices, reloading the page on each page if needed.

这篇关于Webview 内容未加载所有设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆