|
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.FrameLayout;
public class WebviewActivity extends Activity
{
WebView playView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
playView = (WebView) findViewById(R.id.webviewshow);
WebSettings webSettings = playView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setPluginState(PluginState.ON);
playView.loadUrl("file:///android_asset/swf_view.HTML");
}
private void callHiddenWebViewMethod(String name)
{
if (playView != null)
{
try
{
Method method = WebView.class.getMethod(name);
method.invoke(playView);
}
catch (NoSuchMethodException e)
{
Log.i("No such method: " + name, e.toString());
}
catch (IllegalAccessException e)
{
Log.i("Illegal Access: " + name, e.toString());
}
catch (InvocationTargetException e)
{
Log.d("Invocation Target Exception: " + name, e.toString());
}
}
}
@Override
protected void onPause()
{
super.onPause();
playView.pauseTimers();
if (isFinishing())
{
playView.loadUrl("about:blank");
setContentView(new FrameLayout(this));
}
callHiddenWebViewMethod("onPause");
}
@Override
protected void onResume()
{
super.onResume();
callHiddenWebViewMethod("onResume");
}
}
如果你还没有加入callHiddenWebViewMethod(String name)这个反射 ,试着用用吧,然后在 activity's onPause 方法里面调用上面的方法参数为"onPause",同样 activity's onResume 方法里调用"onResume"。
此方法也是本人在网上找来,整理而得,挺好的。发了大家相互学习下。 WebViewTest.rar (416.97 KB, 下载次数: 6) |
|