安卓:setWebViewClient和放大器; setWebChromeClient显示空白页 [英] Android : setWebViewClient & setWebChromeClient displaying blank page
问题描述
我试图加载与setWebViewClient&放一个页面; setWebChromeClient。我可以成功地加载google.com,twitter.com,另一个网页我与JS + CSS + HTML创建,等等。但无法正确加载该网页: http://mozilla.github.com/pdf.js/web/viewer.html
I'm trying to load a page with setWebViewClient & setWebChromeClient. I can successfully load google.com, twitter.com, another web page I create with JS+CSS+HTML, and so on. But impossible to load this webpage correctly: http://mozilla.github.com/pdf.js/web/viewer.html
没有任何人有什么回事,如何解决这个问题?任何想法
Does anybody have any idea on what's going on and how to fix it?
下面的code:
public class MyActivity extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shelf);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setWebChromeClient(new WebChromeClient(){
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d(Utils.tConsole, cm.message()
+ " -- From line " + cm.lineNumber()
+ " of " + cm.sourceId()
);
return true;
}
});
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://mozilla.github.com/pdf.js/web/viewer.html");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_shelf, menu);
return true;
}
}
相应的布局code:
The code of the corresponding layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black"
>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
和的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hey"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:screenOrientation= "landscape"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.hey.MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
任何帮助将非常AP preciated! 谢谢你。
Any help will be very appreciated! Thank you.
推荐答案
第一个问题是shouldOverrideUrlLoading(),将其删除或替换为:
The first problem was in shouldOverrideUrlLoading(), remove it or replace it with:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.myHost.com")) {
// This is my web site, do not override; let WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site
// Launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
现在有一个问题:web视图似乎无法载入大型文件。 我可以显示小的网页,但大页永远不会结束加载。
There is now another problem: the webview seems to be unable to load large files. I can display small web pages, but large pages never end up to load.
有什么办法来调的WebView或意见?
Is there any way to "tune" WebView or advices?
这篇关于安卓:setWebViewClient和放大器; setWebChromeClient显示空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!