Here is my Code:
public class SampleFB1Activity extends Activity {
WebView web2,childView =null;
private LinearLayout parentLayout;
private Activity MyActivity;
private String requestUrl="http://example.com/test.html";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON);
parentLayout =(LinearLayout)findViewById(R.id.parentlayout);
MyActivity = this;
web2 = new WebView(this);
web2.setLayoutParams(getLayoutParams());
web2.setWebViewClient(new FaceBookClient());
web2.setWebChromeClient(new MyChromeClient());
web2.getSettings().setJavaScriptEnabled(true);
web2.getSettings().setAppCacheEnabled(true);
web2.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web2.getSettings().setSupportMultipleWindows(true);
web2.getSettings().setSupportZoom(true);
web2.getSettings().setBuiltInZoomControls(true);
parentLayout.addView(web2);
web2.loadUrl(requestUrl);
}
private LayoutParams getLayoutParams() {
// TODO Auto-generated method stub
return new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
}
final class MyChromeClient extends WebChromeClient{
#Override
public boolean onCreateWindow(WebView view, boolean dialog,
boolean userGesture, Message resultMsg) {
childView = new WebView(SampleFB1Activity.this);
childView.getSettings().setJavaScriptEnabled(true);
childView.getSettings().setSupportZoom(true);
childView.getSettings().setBuiltInZoomControls(true);
childView.setWebViewClient(new FaceBookClient());
childView.setWebChromeClient(this);
childView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
parentLayout.addView(childView);
childView.requestFocus();
web2.setVisibility(View.GONE);
WebView.WebViewTransport transport =(WebView.WebViewTransport)resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
#Override
public void onProgressChanged(WebView view, int newProgress) {
MyActivity.setProgress(newProgress*100);
}
#Override
public void onCloseWindow(WebView window) {
parentLayout.removeViewAt(parentLayout.getChildCount()-1);
childView =null;
web2.setVisibility(View.VISIBLE);
web2.requestFocus();
}
}
private class FaceBookClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("REQUEST URL",url);
return false;
}
}
#Override
public void onBackPressed() {
if(childView != null && parentLayout.getChildCount()==2){
childView.stopLoading();
parentLayout.removeViewAt(parentLayout.getChildCount()-1);
if(web2.getVisibility() == View.GONE)
web2.setVisibility(View.VISIBLE);
}else{
super.onBackPressed();
}
}
In version 3 I am able to see only half comment box and in 4 instead of comment box
it is showing button (Login to facebook to post comment) but will not display comment box.
Please help...
Related
Need some advice. I want to be able to redirect the user to a specific link in WebView. Example: we go to the first link and if it directs us to "google.com" then we will have to direct the user to "http://test.com". I made an implementation, put a redirect in shouldOverrideUrlLoading, however, after SplashScreen-loading image done its work, a white background appears and that's it. At the same time, if you remove the code for redirection, then after performing its work, the SplashScreen - loading image, the first link opens and the page from the Internet is displayed correctly. How do I redirect to other pages after opening the first one?
public class MainActivity extends AppCompatActivity {
private WebView webView;
private final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://test/start");
new TaskForRedirecting().execute();
}
public class TaskForRedirecting extends AsyncTask<Boolean, Void, Boolean> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Boolean doInBackground(Boolean... booleans) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
Log.d(TAG, "Start loading here");
WebViewClient webViewClient = new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("google.com")) {
view.loadUrl("http://test1.com");
return false;
} else if (url.contains("yahoo.com")) {
view.loadUrl("http://test2.com");
return false;
} else {
}
return true;
}
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().toString() == "google.com") {
view.loadUrl("http://test1.com");
view.loadUrl(request.getUrl().toString());
return false;
} else if (request.getUrl().toString() == "yahoo.com") {
view.loadUrl("http://test2.com");
return false;
}
return true;
}
};
webView.setWebViewClient(webViewClient);
Log.d(TAG, "Do in background: APP is Working!!!");
}
});
return false;
}
#Override
protected void onPostExecute(Boolean success) {
success = false;
if (success) {
Toast toast = Toast.makeText(MainActivity.this, "App is under maintenance!", Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(MainActivity.this, "Let's start to work!", Toast.LENGTH_SHORT);
toast.show();
}
Log.d(TAG, "upload - final! ");
}
}
}
public class SplashScreenActivity extends AppCompatActivity {
long Delay = 6000;
private final String TAG = "SplashScreenActivity";
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash_screen);
new SplashScreen().execute();
}
public class SplashScreen extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void...voids) {
Timer RunSplash = new Timer();
TimerTask ShowSplash = new TimerTask() {
#Override
public void run() {
finish();
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
};
RunSplash.schedule(ShowSplash, Delay);
Log.d(TAG, "ShowSplash - final! ");
return null;
}
}
}
Your implementation needs to change a bit, we don't need to set the webview client inside an AsyncTask, instead, we can set it directly but it should be set before we call loadurl.
I have removed the asynctask, and set the client in onCreate method before calling loadUrl.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
WebViewClient webViewClient = new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("google.com")) {
view.loadUrl("http://test1.com");
return true;
} else if (url.contains("yahoo.com")) {
view.loadUrl("http://test2.com");
return true;
}
return false;
}
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().toString() == "google.com") {
view.loadUrl("http://test1.com");
return true;
} else if (request.getUrl().toString() == "yahoo.com") {
view.loadUrl("http://test2.com");
return true;
}
return false;
}
};
webView.setWebViewClient(webViewClient);
webView.loadUrl("http://test/start");
}
UPDATE
Please check out the shouldOverrideUrlLoading Doc, You should return true when you want to cancel the current load, so when you want to load a different URL, then return true else return false to continue the current load. Returning false means the URL which is being loaded to the webview will continue, your custom URL will not be loaded.
I have a webview in a fragment, the webview has multiple links. I want when the user clicks on one of those links, for example, a Readmore link it opens the in-app browser I created (BrowserActivity). How can I achieve this?
BrowserActivity.java
public class BrowserActivity extends AppCompatActivity {
private String Url ;
private WebView Tecwebview;
private ProgressBar progressBar;
ImageButton back, forward, stop, refresh, homeButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
back = (ImageButton) findViewById(R.id.back_arrow);
forward = (ImageButton) findViewById(R.id.forward_arrow);
stop = (ImageButton) findViewById(R.id.stop);
refresh = (ImageButton) findViewById(R.id.refresh);
homeButton = (ImageButton) findViewById(R.id.home);
progressBar = (ProgressBar) findViewById(R.id.probar);
progressBar.setMax(100);
Tecwebview = (WebView) findViewById(R.id.tecwebview);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Tecwebview.loadUrl(Url);
if (savedInstanceState != null) {
Tecwebview.restoreState(savedInstanceState);
} else {
Tecwebview.getSettings().setJavaScriptEnabled(true);
Tecwebview.getSettings().setUseWideViewPort(true);
Tecwebview.getSettings().setLoadWithOverviewMode(true);
Tecwebview.getSettings().setSupportZoom(true);
Tecwebview.getSettings().setSupportMultipleWindows(true);
Tecwebview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
Tecwebview.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progressBar.setProgress(newProgress);
if (newProgress < 100 && progressBar.getVisibility() == ProgressBar.GONE) {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
if (newProgress == 100) {
progressBar.setVisibility(ProgressBar.GONE);
} else {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
}
});
}
Tecwebview.setWebViewClient(new MyWebViewClient());
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Tecwebview.canGoBack()) {
Tecwebview.goBack();
}
}
});
forward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Tecwebview.canGoForward()) {
Tecwebview.goForward();
}
}
});
stop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Tecwebview.stopLoading();
}
});
refresh.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Tecwebview.reload();
}
});
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Tecwebview.loadUrl("https://google.com");
}
});
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progressBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.browser, menu);
return true;
}
Fragment
public class NewsFragment extends Fragment {
private WebView Tecwebview;
public NewsFragment() {
}
LinearLayout Weblinearlayout;
SwipeRefreshLayout Webswipelayout;
ProgressBar progressBar;
String url = "http://someweb.com/news/";
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
Tecwebview = (WebView) v.findViewById(R.id.tecwebview);
progressBar = (ProgressBar) v.findViewById(R.id.probar);
Weblinearlayout = v.findViewById(R.id.layout);
Webswipelayout = v.findViewById(R.id.swipe);
progressBar.setMax(100);
WebSettings Websettings = Tecwebview.getSettings();
Websettings.setJavaScriptEnabled(true);
Tecwebview.setWebViewClient(new WebViewClient());
Tecwebview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if (progress < 100 && progressBar.getVisibility() == ProgressBar.GONE) {
progressBar.setVisibility(ProgressBar.VISIBLE);
Tecwebview.setVisibility(View.GONE);
}
if (progress == 100) {
progressBar.setVisibility(ProgressBar.GONE);
Tecwebview.setVisibility(View.VISIBLE);
}
}
});
Webswipelayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
Tecwebview.reload();
LoadWeb();
}
});
Tecwebview.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
if (Tecwebview.getScrollY()==0){
Webswipelayout.setEnabled(true);
} else {
Webswipelayout.setEnabled(false);
}
}
});
Tecwebview.setWebViewClient(new HomeFragment.MyCustomWebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Weblinearlayout.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
Weblinearlayout.setVisibility(View.GONE);
Webswipelayout.setRefreshing(false);
super.onPageFinished(view, url);
}
});
LoadWeb();
// This code if for the on back press within webview
Tecwebview.canGoBack();
Tecwebview.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == MotionEvent.ACTION_UP
&& Tecwebview.canGoBack()) {
Tecwebview.goBack();
return true;
}
return false;
}
});
return v;
}
public void LoadWeb() {
Tecwebview.loadUrl(url);
Webswipelayout.setRefreshing(true);
}
This is for browser activity to make the links in browser activity webview only opens in the webview
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
return true;
}
According to my understanding you have a url e.g, www.xyz.com and you want to load your Activity when the user clicks on it.
If that is true then try following code but change the value of targeUrl to your link address and also launch the activity in the area where I have wrote comment...
Tecwebview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
String targetUrl = "https//www.somelinksaddress.com/me/you";
if (targetUrl.equals(url)) {
// Start your activity here
} else {
view.loadUrl(url);
}
return true;
}
});
I have a requirement of placing a progressbar in the actionbar/toolbar. I am able to do it by following this link(http://www.michenux.net/android-refresh-item-action-bar-circular-progressbar-578.html).
However I am facing an issue in order to show and hide the progressbar, following the callback design pattern which I have used here. Below is code snippet -
public interface ICallBack {
void setRefreshActionButtonState(boolean b);
}
public class MyFragment extends Fragment implements View.OnClickListener, ICallBack {
private Menu optionsMenu;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
webView = (WebView) findViewById(R.id.main_web);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl("http://stackoverflow.com/");
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
this.optionsMenu = menu;
getActivity().getMenuInflater().inflate(R.menu.menu_home_base, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
// Logic to load the webview again
}
return super.onOptionsItemSelected(item);
}
#Override
public void setRefreshActionButtonState(boolean refreshing) {
if (optionsMenu != null) {
final MenuItem refreshItem = optionsMenu.findItem(R.id.action_refresh);
if (refreshItem != null) {
if (refreshing) {
refreshItem.setActionView(R.layout.toolbar_indeterminate_progress);
} else {
refreshItem.setActionView(null);
}
}
}
}
}
public class MyWebViewClient extends WebViewClient {
ICallBack callBack;
public MyWebViewClient(Activity context) {
callBack = new MyFragment();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
callBack.setRefreshActionButtonState(true);//Showing the progressbar
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
callBack.setRefreshActionButtonState(false);//Hiding the progressbar
}
}
When setRefreshActionButtonState() gets call then I am getting optionsMenu value as null, resulting not able to show and hide the progressbar.
Can someone help me to figure out that where I am doing wrong.
Thanks,
Can you upload the xml where the item action_refresh is. The problem could be in findItem(R.id.action_refresh);
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment_view frag=new Fragment_view();
FragmentManager manager=getFragmentManager();
FragmentTransaction transaction=manager.beginTransaction();
transaction.add(R.id.fragment,frag,"hey");
transaction.commit();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (inCustomView()) {
hideCustomView();
return true;
}
if ((mCustomView == null) && webView.canGoBack()) {
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Now here variables like inCustomView and hidecustomView are defined in another fragment. So how to add this back button support on activity while using variables from a fragment. So I basically want to implement back button support in Android activity while using the defined variables from a fragment.
public class Fragment_view extends Fragment{
private WebView webView;
private FrameLayout customViewContainer;
private WebChromeClient.CustomViewCallback customViewCallback;
private View mCustomView;
private myWebChromeClient mWebChromeClient;
private myWebViewClient mWebViewClient;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view= inflater.inflate(R.layout.fragment_view, container,false);
customViewContainer = (FrameLayout)view.findViewById(R.id.customViewContainer);
webView = (WebView)view. findViewById(R.id.webView);
mWebViewClient = new myWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSaveFormData(true);
String htmlFile = "file:///" + Environment.getExternalStorageDirectory()
.getPath()
+ "/video_nsta/index.html";
webView.loadUrl(htmlFile);
return view;
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mWebChromeClient.onHideCustomView();
}
#Override
public void onPause() {
super.onPause();
webView.onPause();
}
#Override
public void onResume() {
super.onResume();
webView.onResume();
}
#Override
public void onStop() {
super.onStop();
if (inCustomView()) {
hideCustomView();
}
}
class myWebChromeClient extends WebChromeClient {
#Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
onShowCustomView(view, callback);
}
#Override
public void onShowCustomView(View view,CustomViewCallback callback) {
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
customViewCallback = callback;
}
#Override
public void onHideCustomView() {
super.onHideCustomView();
if (mCustomView == null)
return;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
mCustomView.setVisibility(View.GONE);
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = null;
}
}
class myWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
}
}
it's a matter of properly distributing the back button.
first create a fragment that can handle it:
public abstract class BackButtonFragment extends Fragment{
public boolean onBackPressed(){
return false; // defaults to false
}
}
then you change all your fragments to extend from BackButtonFragment.
Then on your activity you will use the appropriate callback for backbutton (remove the onKeyDown from your activity and use this instead):
#Override public void onBackPressed() {
Fragment f = getFragmentManager().findFragmentById(R.id.fragment);
if(f instanceof BackButtonFragment){
if(((BackButtonFragment)f).onBackPressed())
return;
}
// if fragment didn't use back button do the normal stuff
super.onBackPressed();
}
then inside each one of your fragments you will override the method onBackPressed and return the correct value true or false depending on your needs.
i was working on a webView had it working but the flash videos didn't work.
After a little bit of searching i found a webview code that displays videos.
webview video
this is my old code
private static final String LOG_TAG = "Web";
private WebView mWebView;
public static final String URL = "";
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.web);
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
String turl = getIntent().getStringExtra(URL);
mWebView.loadUrl(turl);
;
}
#Override
public void onBackPressed() {
finish();
}
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging
* your javascript.
*/
final class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message,
JsResult result) {
Log.d(LOG_TAG, message);
result.confirm();
return true;
}
}
so i replaced it with the mainactivity from the source and added
String turl = getIntent().getStringExtra(URL);
and
public static final String URL = "";
and made some changes so it loads the class names i use
so now i've got this
private WebView webView;
public static final String URL = "";
private FrameLayout customViewContainer;
private WebChromeClient.CustomViewCallback customViewCallback;
private View mCustomView;
private myWebChromeClient mWebChromeClient;
private myWebViewClient mWebViewClient;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
webView = (WebView) findViewById(R.id.webView);
mWebViewClient = new myWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSaveFormData(true);
String turl = getIntent().getStringExtra(URL);
webView.loadUrl(turl);
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mWebChromeClient.onHideCustomView();
}
#Override
protected void onPause() {
super.onPause(); //To change body of overridden methods use File | Settings | File Templates.
webView.onPause();
}
#Override
protected void onResume() {
super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
webView.onResume();
}
#Override
protected void onStop() {
super.onStop(); //To change body of overridden methods use File | Settings | File Templates.
if (inCustomView()) {
hideCustomView();
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (inCustomView()) {
hideCustomView();
return true;
}
if ((mCustomView == null) && webView.canGoBack()) {
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
class myWebChromeClient extends WebChromeClient {
private Bitmap mDefaultVideoPoster;
private View mVideoProgressView;
#Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates.
}
#Override
public void onShowCustomView(View view,CustomViewCallback callback) {
// if a view already exists then immediately terminate the new one
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
customViewCallback = callback;
}
#Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = LayoutInflater.from(Web.this);
mVideoProgressView = inflater.inflate(R.layout.video_progress, null);
}
return mVideoProgressView;
}
#Override
public void onHideCustomView() {
super.onHideCustomView(); //To change body of overridden methods use File | Settings | File Templates.
if (mCustomView == null)
return;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
// Hide the custom view.
mCustomView.setVisibility(View.GONE);
// Remove the custom view from its container.
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = null;
}
}
class myWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url); //To change body of overridden methods use File | Settings | File Templates.
}
}
i use this code for my button to open the url in webview
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Intent k = new Intent(this, Web.class);
k.putExtra(com.papers.test.Web.URL,
"http://www.telegraaf.mobi");
startActivity(k);
break;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onlinekranten);
View secondButton = findViewById(R.id.button1);
secondButton.setOnClickListener(this);
}
in my old web.class this worked just fine but now when i press the button i'm getting a fc, can anyone help me out with this problem?
logcat
06-07 12:38:55.310: E/AndroidRuntime(3236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.papers.test/com.papers.test.Web}: java.lang.NullPointerException
Its looks like your button needs to be declared
I like to do it above onCreate to use it any where
Button secondButton;