我想知道为什么在我将操作系统版本从2.3.6更新到4.0.3之后我无法在我的WebView中播放youtube.com,下面是我的代码
<WebView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.55"
android:scrollbars="none"
/>
这里我想添加“android:hardwareAccelerated =”true“但不允许在eclip中添加此行:(
<application
android:icon="@drawable/ic_perry"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name=".MeasSokSopheaActivity"
android:label="@string/app_name"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".video" />
</application>
public class video extends Activity {
private WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
if(!haveNetworkConnection())
{
AlertDialog alertDialog = new AlertDialog.Builder(video.this).create();
alertDialog.setTitle("Connection Error!");
alertDialog.setMessage("Please connected to the internet in order to use this apps.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//here you can add functions
} });
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.show();
}
else
{
mWebView = new WebView(this);
mWebView = (WebView) findViewById(R.id.video);
mWebView.setWebViewClient(new myWebClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("http://domain/videoyoutube.php");
}
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onDestroy()
{
if(mWebView != null)
{
mWebView.destroy();
mWebView = null;
}
super.onDestroy();
}
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
}