java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:2772)
at android.webkit.WebViewCore$EventHub.access$13800(WebViewCore.java:1434)
at android.webkit.WebViewCore.removeMessages(WebViewCore.java:2884)
at android.webkit.WebView.sendOurVisibleRect(WebView.java:4140)
at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:1022)
at android.webkit.ZoomManager.access$2100(ZoomManager.java:57)
at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:1596)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
当我设置“webSettings.setPluginState(PluginState.ON)”时会出现这个问题,
这是我的代码:
package com.etongwl.test.androidtestdemo;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
public class WebViewActivity extends Activity {
/**
* 浏览器对象
*/
private WebView webView = null;
/**
* 进度条
*/
private ProgressBar progressBar = null;
/**
* 加载的URL
*/
private String url = null;
/**
* handler
*/
@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == 1) {
progressBar.setProgress(msg.arg1);
} else if (msg.what == 2) {
progressBar.setVisibility(ProgressBar.VISIBLE);
} else if (msg.what == 3) {
progressBar.setVisibility(ProgressBar.GONE);
}
};
};
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
/**
* 获得屏幕的宽高
*/
DisplayMetrics dm = new DisplayMetrics();
// 取得窗口属性
getWindowManager().getDefaultDisplay().getMetrics(dm);
// 窗口的宽度
int screenWidth = dm.widthPixels;
// 窗口高度
int screenHeight = dm.heightPixels;
LinearLayout layout = new LinearLayout(this);
LayoutParams params = new LayoutParams(screenWidth, screenHeight);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(params);
layout.setBackgroundColor(Color.WHITE);
setContentView(layout);
// 获得状态栏高度
int statusBarHeight = getStatusHeight(this);
Intent intent = getIntent();
url = intent.getStringExtra("URL");
// 标题
RelativeLayout view = (RelativeLayout) getLayoutInflater().inflate(
R.layout.webviewheader, null);
Button back = (Button) view.findViewById(R.id.btn_back);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
view.setLayoutParams(new LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
int w = RelativeLayout.MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED);
int h = RelativeLayout.MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED);
view.measure(w, h);
int x = view.getMeasuredHeight();
layout.addView(view);
// 进度条
progressBar = new ProgressBar(this, null,
android.R.attr.progressBarStyleHorizontal);
LinearLayout.LayoutParams param = new android.widget.LinearLayout.LayoutParams(
screenWidth - 2, 3);
param.setMargins(1, 2, 1, 2);
progressBar.setLayoutParams(param);
progressBar.setMax(100);
layout.addView(progressBar);
// webView浏览器
webView = new WebView(this);
LinearLayout.LayoutParams paramW = new android.widget.LinearLayout.LayoutParams(
screenWidth, screenHeight - x - 7 - statusBarHeight);
webView.setLayoutParams(paramW);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
// webSettings.setDisplayZoomControls(true);
// webSettings.setUseWideViewPort(true);
// webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
// webSettings.setAllowFileAccessFromFileURLs(true);
// webSettings.setAllowUniversalAccessFromFileURLs(true);
// webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
// webSettings.setEnableSmoothTransition(true);
// webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setPluginsEnabled(true);
webSettings.setPluginState(PluginState.ON);
webView.setBackgroundColor(Color.WHITE);
layout.addView(webView);
webView.setWebChromeClient(new WebChromeClient() {
/*
* (non-Javadoc)
*
* @see
* android.webkit.WebChromeClient#onProgressChanged(android.webkit
* .WebView, int)
*/
@Override
public void onProgressChanged(WebView view, int newProgress) {
// super.onProgressChanged(view, newProgress);
Message msg = handler.obtainMessage();
msg.what = 1;
msg.arg1 = newProgress;
msg.sendToTarget();
}
});
webView.setWebViewClient(new WebViewClient() {
/*
* (non-Javadoc)
*
* @see
* android.webkit.WebViewClient#shouldOverrideUrlLoading(android
* .webkit.WebView, java.lang.String)
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
/*
* (non-Javadoc)
*
* @see
* android.webkit.WebViewClient#onPageStarted(android.webkit.WebView
* , java.lang.String, android.graphics.Bitmap)
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// super.onPageStarted(view, url, favicon);
Message msg = handler.obtainMessage();
msg.what = 2;
msg.sendToTarget();
}
/*
* (non-Javadoc)
*
* @see
* android.webkit.WebViewClient#onPageFinished(android.webkit.WebView
* , java.lang.String)
*/
@Override
public void onPageFinished(WebView view, String url) {
// super.onPageFinished(view, url);
Message msg = handler.obtainMessage();
msg.what = 3;
msg.sendToTarget();
}
});
if (url != null) {
webView.loadUrl(url);
} else {
webView.loadUrl("一个swf文件路径");
}
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
finish();
// android.os.Process.killProcess(android.os.Process.myPid());
}
}
/**
*
* @Des: 获得状态栏高度
* @param activity
* @return
*/
public int getStatusHeight(Activity activity) {
int statusHeight = 0;
Rect localRect = new Rect();
activity.getWindow().getDecorView()
.getWindowVisibleDisplayFrame(localRect);
statusHeight = localRect.top;
if (0 == statusHeight) {
Class<?> localClass;
try {
localClass = Class.forName("com.android.internal.R$dimen");
Object localObject = localClass.newInstance();
int i5 = Integer.parseInt(localClass
.getField("status_bar_height").get(localObject)
.toString());
statusHeight = activity.getResources()
.getDimensionPixelSize(i5);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
return statusHeight;
}
}
我的项目由android 2.2创建并在android 4.0.4上运行无论安装的是android2.2还是android4.0的flash播放器都可以正常运行。如果我通过 android 4.0.4 创建项目并正常运行 android 4.0.4 为什么?请帮帮我谢谢