WebView won't scroll for certain web page - android

I'm trying to load Time.com on my WebView.
Loading itself works fine, but the loaded page is not scrollable.
It works well with built-in browser, chrome browser
If I use other url(ex. http://www.google.com/), it works fine.
I think the problem is in the web page(html), but I can't figure out what's the problem.
Below is the code, though there's nothing special.
MainActivity.java
package com.yooiistudios.webviewperformance;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView)findViewById(R.id.webView);
mWebView.setWebViewClient(new NewsWebViewClient());
mWebView.loadUrl("http://www.time.com/");
}
private class NewsWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

After some research, I found out that HTML5WebView works for my case.
Also I had a problem that for some video in webpage won't play on default android webview, and HTML5WebView also solved that problem.
Source code it self is a bit dirty and cluttered, it works fine.
Anyway, I leave a link here. Hope this helps someone who has same problem.
link: https://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java

Related

VideoView not showing video only audio coming in android 4.0.3 only

i have a basic example app to play video from res/raw. My problem is that it is not working(only audio playing) in android 4.0.3, but working in 3.2 , 4.3 , 4.4 (emulators). And on a real device (micromax canvas 4 with android 4.2.1) it says app has stopped responding.?
My question how can i play it on all android and why is it not responding on my moblie??
and i have already searched on stackoverflow with no positive result..
PLEASE HELP THANKS
this is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<VideoView
android:id="#+id/vidvew"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
this is my .java file
package com.example.tryit;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.VideoView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView vv = (VideoView) findViewById(R.id.vidvew);
String fileName = "android.resource://" + getPackageName() + "/" +R.raw.cs;
vv.setVideoURI(Uri.parse(fileName));
vv.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Check the encoding of the video properly. Android allows only certain types of file types to be played in the app. Please see the link below for more information -
http://developer.android.com/guide/appendix/media-formats.html

youtube output on my app without using a standard browser with webview

I want to put the webversion of youtube in my application where you can do everything(like watch and search videos,..) without using a standard browser. I have written this code but every time pop ups which browser I want to use (like Google chrome,..)but I want to let it display on my appscreen and I have set the permission of internet already.
here the code:
youtube.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
youtube.java:
package com.example.listentomusic;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Youtube extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube);
WebView wv = (WebView)findViewById(R.id.webView1);
wv.loadUrl("http://www.youtube.com");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
You need to create your CustomWebViewClient & set it to your webView.
Like this -
private class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Now set this CustomeWebViewClient to your webView-
WV.setWebViewClient(new CustomWebViewClient());
Also main(String[] args) is of no use, remove it.

playing video on android webview does not fullscreen

I am making a webview application which shows pages they have html5 videos in it. when I tap the fullscreen, video dissapears.
when I searching same problems, saw this question, which is same problem with me, and thought 2nd answer (here) fits for me also.
Even I use classes given in the answer, I am still having these errors and application stoped.
05-03 13:41:50.064: E/AndroidRuntime(19292): FATAL EXCEPTION: main
05-03 13:41:50.064: E/AndroidRuntime(19292): java.lang.NullPointerException
05-03 13:41:50.064: E/AndroidRuntime(19292): at com.zapkolik.mayis.VideoEnabledWebChromeClient.onShowCustomView(VideoEnabledWebChromeClient.java:132)
05-03 13:41:50.064: E/AndroidRuntime(19292): at android.webkit.HTML5VideoFullscreen.enterFullscreen(HTML5VideoFullscreen.java:239)
05-03 13:41:50.064: E/AndroidRuntime(19292): at android.webkit.HTML5VideoView.enterFullscreenVideoState(HTML5VideoView.java:544)
05-03 13:41:50.064: E/AndroidRuntime(19292): at android.webkit.HTML5VideoViewProxy$VideoPlayer.enterFullscreenVideo(HTML5VideoViewProxy.java:182)
05-03 13:41:50.064: E/AndroidRuntime(19292): at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:479)
05-03 13:41:50.064: E/AndroidRuntime(19292): at android.os.Handler.dispatchMessage(Handler.java:99)
.
.
.
my activity is here:
MainActivity.java
package com.zapkolik.mayis;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.text.method.HideReturnsTransformationMethod;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity {
private VideoEnabledWebView webView;
private VideoEnabledWebChromeClient webChromeClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Save the web view
webView = (VideoEnabledWebView) findViewById(R.id.webView);
// Initialize the VideoEnabledWebChromeClient and set event handlers
View nonVideoLayout = findViewById(R.id.nonVideoLayout); // Your own view, read class comments
ViewGroup videoLayout = (ViewGroup) findViewById(R.layout.video_layout); // Your own view, read class comments
View loadingView = getLayoutInflater().inflate(R.layout.loading_video, null);
// Your own view, read class comments
final Activity activity = this;
webChromeClient = new VideoEnabledWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView) // See all available constructors...
{
// Subscribe to standard events, such as onProgressChanged()...
#Override
public void onProgressChanged(WebView view, int progress)
{
activity.setProgress(progress * 1000);
}
};
webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback()
{
#Override
public void toggledFullscreen(boolean fullscreen)
{
// AlertDialog alertDialog = new AlertDialog.Builder(activity).create(); //Read Update
// alertDialog.setTitle("hi");
// alertDialog.setMessage("this is my app");
}
});
webView.setWebChromeClient(webChromeClient);
webView.setWebViewClient(new WebViewClient());
// Navigate everywhere you want, this classes have only been tested on YouTube's mobile site
webView.loadUrl("http://m.youtube.com");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onBackPressed()
{
// Notify the VideoEnabledWebChromeClient, and handle it ourselves if it doesn't handle it
if (!webChromeClient.onBackPressed())
{
if (webView.canGoBack())
{
webView.goBack();
}
else
{
// Close app (presumably)
super.onBackPressed();
}
}
}
}
and layouts are:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nonVideoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.zapkolik.mayis.VideoEnabledWebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
loading_video.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/center"
android:gravity="center|center_vertical"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="208dp"
android:layout_height="0dip"
android:layout_weight="0.39" />
</LinearLayout>
video_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<VideoView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/videoView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I could not figure out why I am getting errors when I tap the fullscreen button.

My embed video is not playing in WebView

I want to play this video in webview in android
http://www.youtube.com/embed/hLw8RZ10PLo?showsearch=0&autoplay=1&rel=0
But searched for it and i have implemented everything what i got
here is my code
package com.example.webapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView)findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
final WebSettings.PluginState ON = webSettings.getPluginState().ON;
webSettings.setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36");
webSettings.setPluginState(ON);
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
webSettings.setAllowFileAccess(true);
myWebView.loadUrl("http://www.youtube.com/embed/hLw8RZ10PLo?showsearch=0&autoplay=1&rel=0");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and this is my xml
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webview" >
</WebView>
I am playing this video in my android 2.3.6 version and in my manifest file, I have used
android:harwareAccelerated="true"
But still my video is not running.
Can Anybody help me, I am stuck in this problem from yesterday.
Use Webview, Create a string for html tags, add iframe tage and pass the height and width of the video and url. and load the string in webview
<iframe width="420" height="345"
src="http://www.youtube.com/embed/XGSy3_Czz8k">
</iframe>
Add the string in loaddata of webview
webView.loadData(strHTMLTags, "text/html", "UTF-8");

Pop-Up Window at inital start up, of android application

I am trying to find a code that will do a popup at the initial start up on an installed app. Much like a changelog that is starting to appear in more and more apps.
I have found some similar codes, but being a beginner I haven't been able to figure out where to exactly put the code in and I always have tons of errors that still do not work once I try and fix them.
I am working in Eclipse with an android project, and I'm using a webview to show a website.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="false"/>
</LinearLayout>
Java File:
package com.A2Ddesigners.WhatThe;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.KeyEvent;
public class Whatthe extends Activity {
WebView webview;
/** Called when the activity is first created. */
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(50);
webview.getSettings().setUseWideViewPort(true);
webview.loadUrl("http://mdsitest2.com/");
}
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
Using My this code you can show popup on any type of view on intial time of activity.
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
public class PopupDispaly extends Activity {
private PopupWindow outComePopup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tiwter_login);
final View anyView = findViewById(R.id.popo_up); // define heade your view
anyView.postDelayed(new Runnable() {
#Override
public void run() {
callFirstToolTip(anyView);
}
}, 5000); // hear you can put your delay time like 5000 mls
}
public void callFirstToolTip(View view) {
Log.i("Started Info","popup");
View layout = LayoutInflater.from(PopupDispaly.this).inflate(R.layout.popup_copy_delete, null); // define hear your layout file id.
LinearLayout layCopyDelete = (LinearLayout) layout.findViewById(R.id.layCopyDelete);// hear define your id of sub lay like LinearLayout.
outComePopup = new PopupWindow(layout);
outComePopup.setFocusable(true);
layCopyDelete.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
outComePopup.setWidth(layCopyDelete.getMeasuredWidth());
outComePopup.setHeight(layCopyDelete.getMeasuredHeight());
outComePopup.setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
outComePopup.setOutsideTouchable(true);
outComePopup.showAsDropDown(view);
}
}
And my Custome View layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/got_it_bg"
android:layout_gravity="center_horizontal"
android:id="#+id/layCopyDelete"
android:layout_marginLeft="100dp"
android:orientation="horizontal">
</LinearLayout>
Sounds like you should use a custom dialog box. http://developer.android.com/guide/topics/ui/dialogs.html
There's a code example at the bottom of the page. To show it, you can call onCreateDialog(int) from inside your main activity in its onCreate() method.
PopupWindow.showAsDropDown() in a delayed process can solve this problem, you can execute the show popupWindow in onCreate() method by 0.5s delay.
You should use PopupWindow.showAtLocation but use the post method of the one of the views on your activity. you can also use the root view of the activity using findViewById(android.R.id.content).
You code should look like this:
View anyView = findViewById(R.id.anyView);
anyView.post(new Runnable()
{
#Override
public void run()
{
// Create and show PopupWindow
}
});

Categories

Resources