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.
Related
I'd like to make a menu with a delete option. The actual delete functionality isn't made yet because at the moment I can't see the top bar in my app.
Main layout (activity_main.xml):
<?xml version="1.0" encoding="utf-8"?>
<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="billy.cs436.placebadgesapp.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/newPlace"
android:text="#string/newPlaceButton"
/>
</RelativeLayout>
Menu layout (main.xml):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/deleteMenu"
android:icon="#drawable/clear"
android:title="#string/deleteMenu"
app:showAsAction="ifRoom"
/>
</menu>
Main activity (MainActivity.java):
package billy.cs436.placebadgesapp;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
Button newPlace;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
newPlace = (Button) findViewById(R.id.newPlace);
newPlace.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), setLocation.class);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the main; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);//Menu Resource, Menu
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.deleteMenu) {
// if there are no badges, toast message saying so (needs implementing)
Toast.makeText(this, "There are no badges to delete!", Toast.LENGTH_SHORT).show();
//else clear all badges
} else {
Toast.makeText(this, "Badges cleared!", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
Can anyone tell my why the New Place button is the only thing that shows up when this is run?
EDIT:
#T.S has the correct answer. Thank you.
Change your class to extend AppCompatActivity instead of Activity.
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
I want to display webview below progressbar. How to do it ?
My code is as below :
<FrameLayout
android:id="#+id/flWeb"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ProgressBar
android:id="#+id/pbWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top" />
<WebView
android:id="#+id/wvWebsite"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
I used this and solved my problem...
<FrameLayout
android:id="#+id/flWebpre"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/wvWebsite"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ProgressBar
android:id="#+id/pbWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_gravity="center_horizontal" />
</FrameLayout>
This is the code i have used to show the progress:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
WebView mWvUrl;
#Override
protected void onCreate(Bundle savedInstanceState) {
final Activity activity=this;
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
activity.setProgressBarIndeterminateVisibility(false);
mWvUrl = (WebView) findViewById(R.id.wv_url);
mWvUrl.getSettings().setJavaScriptEnabled(true);
Button btnLoad = (Button) findViewById(R.id.btn_load);
btnLoad.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EditText etUrl = (EditText) findViewById(R.id.et_url);
mWvUrl.loadUrl(etUrl.getText().toString());
activity.setProgressBarIndeterminateVisibility(true);
}
});
mWvUrl.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
/** This prevents the loading of pages in system browser */
return false;
}
/** Callback method, executed when the page is completely loaded */
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Toast.makeText(getBaseContext(),
"Page loaded Completely",
Toast.LENGTH_SHORT).show();
/** Hiding Indeterminate Progress Bar in the title bar*/
activity.setProgressBarIndeterminateVisibility(false);
}
});
}
#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;
}
}
You need another Layout. The FrameLayout is not the better way to do alignement between components. If you are using a FrameLayout, components will be superimposed. I suggest you to use a LinearLayout vertical or a RelativeLayout.
Try this:
<?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:orientation="vertical" >
<ProgressBar
android:id="#+id/pbWebsite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top" />
<WebView
android:id="#+id/wvWebsite"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I am trying to display a interactive map that I have created with imapbuilder. The problem is when i load it in my webview I just get a blank screen. I have tried everything (am just wondering if my device can't handle flash have got sgs2 and Motorola xoom2 10.1in tablet with ICS on both).
Here is my code for 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/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
For my .java;
import android.os.Bundle;
import android.app.Activity;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
public class MainActivity extends Activity {
private Handler mHandler = new Handler();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags
(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
WebView view=(WebView)findViewById(R.id.webview);
view.getSettings().setPluginsEnabled(true);
view.loadUrl("file:///android_asset/Interactive.htm");
view.addJavascriptInterface(new MyJavaScriptInterface(), "Android");
}
final class MyJavaScriptInterface
{
public void ProcessJavaScript(final String scriptname, final String args)
{
mHandler.post(new Runnable()
{
public void run()
{
//Do your activities
}
});
}
}
}
In my assets folder is the Interactive.htm and sub folder with the flash files and stuff exported from the software I used.
So where am I going wrong?
Did you add this permission to your manifest file?
<uses-permission android:name="android.permission.INTERNET" />
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
}
});