Webview内容未加载所有设备

时间:2022-12-06 09:49:05

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将数据从服务器加载到设备。但它没有加载少数设备,如Moto x和在一些设备加载,但当从webview页面转到另一页面,然后回到同一页面然后webview内容丢失。这发生在Xperia z.Other设备三星,Xiomi everthing工作正常。

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

问题是什么以及如何解决这个问题所以webview数据渲染所有设备都很好。

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

here the Xml code

这里是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" /> 

Here is the Java code:

这是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);

1 个解决方案

#1


0  

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

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

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

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

然后,尽管您使用此方法,但似乎您没有从URL加载内容:

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

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,则使用loadDataWithBaseURL;否则,如果从本地加载,则使用其他方法,如:webview.loadData(summary,“text / html”,null);

EDIT: 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.

编辑:然后根据您的最新评论,我将保存用户在集合中导航的Url,甚至将滚动保存在这些特定设备中。然后听Back按钮并浏览这些设备中的保存URL,如果需要,在每个页面上重新加载页面。

#1


0  

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

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

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

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

然后,尽管您使用此方法,但似乎您没有从URL加载内容:

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

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,则使用loadDataWithBaseURL;否则,如果从本地加载,则使用其他方法,如:webview.loadData(summary,“text / html”,null);

EDIT: 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.

编辑:然后根据您的最新评论,我将保存用户在集合中导航的Url,甚至将滚动保存在这些特定设备中。然后听Back按钮并浏览这些设备中的保存URL,如果需要,在每个页面上重新加载页面。