I am creating an android app in which I just want to load a youtube "page" of a user in a webview. So for that there are two clients WebViewClient & WebChromeClient and to play videos we have to use WebChromeClient, but when i load the youtube page using WebChromeClient, my main activity gives me an option to open it in either chrome browser or youtube app but i want to load the page in the same webview.
NOte: It is working fine on android 4.2.2 but I am not able to make it work on 4.4+ versions
MainActivity.java
public class MainActivity extends Activity {
public static final String PAGE_URL = "http://www.youtube.com/jaambhaari";
final Activity activity = this;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.setWebViewClient(new WebViewClient(){});
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress){
activity.setTitle("Loading...");
if(progress == 100){
activity.setTitle(R.string.app_name);
}
}
});
webview.loadUrl(PAGE_URL);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jaambhaari.jaambhaari"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme" >
<!-- Splash screen -->
<activity
android:name="com.jaambhaari.jaambhaari.SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:scaleType="fitXY"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:mimeType="application/*" />
<data android:mimeType="audio/*" />
<data android:mimeType="image/*" />
<data android:mimeType="message/*" />
<data android:mimeType="multipart/*" />
<data android:mimeType="text/*" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<!-- Main activity -->
<activity
android:name="com.jaambhaari.jaambhaari.MainActivity"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Following are the texts I get in the console when i run it on android 4.4.2 :
- Viewport target-densitydpi is not supported
- FBIOGET_FSCREENINFO failed
- Async pixel transfers not supported
The new webview is a mess. Lot many things are broken. I wanted to add this as a comment, but dont have enough reputation. You can go through this bug report (html video support)
https://code.google.com/p/chromium/issues/detail?id=239864
Problems are so severe, that developers are crying foul to get the old webview back https://code.google.com/p/android/issues/detail?id=62293