Jquery and CSS animation not working in ANDROID Webview application - javascript

I am trying to make a Webview for my website. But i have one problem with jquery code.
This is my DEMO site. In this demo site you can see when you click the image then detail div will open with animation.
But that detail is not open when i click the image.
Note: I am a new in Android
Here is my application code for Webview:
package ecowebtr.ecowebtr;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView webView;
private CustomWebViewClient webViewClient;
private String Url = "http://www.ecowebtr.com/";
ProgressDialog mProgressDialog;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Loading...");
webViewClient = new CustomWebViewClient();
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(webViewClient);
webView.loadUrl(Url);
}
private class CustomWebViewClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if(!mProgressDialog.isShowing())
{
mProgressDialog.show();
}
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(mProgressDialog.isShowing()){
mProgressDialog.dismiss();
}
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
}
}
public void onBackPressed()
{
if(webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}

Try this code to solve:
webView = (WebView) findViewById(R.id.web);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
settings.setDatabasePath("/data/data/" + this.getPackageName() + "/databases/");
}

Related

Closing android webview when specific url load?

I have basic android webview.it is a signup page.i want to close this webview after signup and start new intent.im new to this please help.this is my code.
public class signupweb extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signupweb);
webView = (WebView) findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl("http://aaa.freeasphost.net/signup.aspx");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.equals("http://aaa.freeasphost.net/MainPanel.aspx")) {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
return false;
} else {
return true;
}
}
// }
I tried this but not working.it stuck in the signup page
You need to pass context to start new activity. Try this:
private class MyWebViewClient extends WebViewClient {
private Context context;
public MyWebViewClient(Context context) {
this.context = context;
}
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.equals("http://aaa.freeasphost.net/MainPanel.aspx")) {
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
context.startActivity(intent);
return false;
} else {
return true;
}
}

How to load a custom error page in webview when no internet connection?

Im trying to find out how I add a custom offline page to my webview app. The app works well I just feel like a custom offline page would look much better! I have looked at some answers online but they dont seem to work any more :(. I hope someone can help!
Here is my Main code is (Made in the android studio):
package com.rizwan.yvsse;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.onesignal.OneSignal;
public class MainActivity extends AppCompatActivity {
WebView webView;
ProgressBar progressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
Intent intent = new Intent(MainActivity.this, splash_screen.class);
startActivity(intent);
progressBar= (ProgressBar)findViewById(R.id.progressBar);
webView = (WebView) findViewById(R.id.webview);
String url="https://yvsse.com/billing/";
webView.loadUrl(url);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new HelloWebViewClient());
}
#Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
// set title
alertDialogBuilder.setTitle("Exit");
// set dialog message
alertDialogBuilder
.setMessage("Do you really want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
private class HelloWebViewClient 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 webView, String url) {
webView.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(view.GONE);
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
}
}
Thank you!
Overrride the onReceivedError method and check internet connectivity inside it to confirm that the url failed because of the internet connectivity
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if(!isappOnline()) {
webView.loadUrl("file:///android_asset/error.html");
}
}
private boolean isappOnline() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null;
}
also add your fallback page in assets folder src/main/assets/

Hide Progress Bar after Webview loaded

I'm new on android studio. My problem is that the progress bar does not stop spinning after the webview finished loading.
I have also tried with this one-
progressbar.setVisibility(View.VISIBLE); //to show
progressbar.setVisibility(View.GONE); // to hide
But the error not resolved
My first Fragment Java Class-
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class firstfragment extends Fragment{
public WebView mywebview2;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.first_layout, container, false);
mywebview2 = (WebView) v.findViewById(R.id.WebView);
mywebview2.loadUrl("https://m.youtube.com");
mywebview2.setWebViewClient(new WebViewClient());
// Enable Javascript
WebSettings webSettings = mywebview2.getSettings();
webSettings.setJavaScriptEnabled(true);
AdView mAdView = (AdView) v.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
return v;
}
public void onPageFinished(WebView view,String url){
ProgressBar progressbar = (ProgressBar) view.findViewById(R.id.progressBar2);
progressbar.setVisibility(View.VISIBLE); //to show
progressbar.setVisibility(View.GONE); // to hide
}
}
You should not declare this line ProgressBar progressbar = (ProgressBar) view.findViewById(R.id.progressBar2); inside onPageFinished . you have to declare it inside onCreateView
your code:
public void onPageFinished(WebView view,String url){
ProgressBar progressbar = (ProgressBar) view.findViewById(R.id.progressBar2);
progressbar.setVisibility(View.VISIBLE); //to show
progressbar.setVisibility(View.GONE); // to hide
}
here, your view.findViewById(R.id.progressBar2) is referring to your WebView view which has nothing to do with your progressbar.
So it should be-
private ProgressBar progressbar;
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.first_layout, container, false);
mywebview2 = (WebView) v.findViewById(R.id.WebView);
//here
progressbar = (ProgressBar) v.findViewById(R.id.progressBar2);
// Enable Javascript
WebSettings webSettings = mywebview2.getSettings();
webSettings.setJavaScriptEnabled(true);
AdView mAdView = (AdView) v.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
myWebView2.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url) {
progressbar.setVisibility(View.VISIBLE);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
progressbar.setVisibility(View.GONE);
return true;
}
});
mywebview2.loadUrl("https://m.youtube.com");
return v;
}
public class firstfragment extends Fragment {
public WebView mywebview2;
private ProgressBar progressbar;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.first_layout, container, false);
mywebview2 = (WebView) v.findViewById(R.id.WebView);
mywebview2.setWebViewClient(new WebViewClient());
progressbar = (ProgressBar) view.findViewById(R.id.progressBar2);
// Enable Javascript
WebSettings webSettings = mywebview2.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebview2.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressbar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressbar.setVisibility(View.GONE);
}
});
mywebview2.loadUrl("https://m.youtube.com");
AdView mAdView = (AdView) v.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
return v;
}
}
#Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
progressBar.setVisibility(view.GONE);
}
try this with below code you can load progress as per data load in web view and after page loading progress bar hide
String url = "";
webView = (WebView) findViewById(R.id.web);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(url);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
progressBar.setMax(100);
progressBar.setProgress(1);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// progressDialog.hide();
progressBar.setVisibility(View.GONE);
}
});
}
layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="#+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:layout_marginTop="-7dp"
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#android:color/transparent"
android:indeterminate="false"
android:max="100"
android:progress="1"
android:theme="#style/ProgressbarTheme" />
</RelativeLayout>
ask me in case of any query

android how to show PopupMenu in webview like GMail

I want to show PopupMenu in webview on my app like GMail.
Here is my code:
webView.addJavascriptInterface(new WebAppInterface(getActivity()), "ScriptToAndroid");
<div class="moreover_icon" onclick="showPopup('file_attach_path', event)">
<img class="overflow_icon" src="android_moreover_icon"/>
</div>
<script type="text/javascript">
function showPopup(file_path, event) {
ScriptToAndroid.showPopupDialog(file_path, pos_x, pos_y);
}
</script>
#JavascriptInterface
public void showPopupDialog(String filePath, int x, int y) {
//show PopupMenu
}
Use a WebViewClient
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setWebViewClient(new WebClient(this));
intercept shouldOverrideUrlLoading()
public class WebClient extends WebViewClient {
MainActivity mainActivity;
public WebClient(MainActivity activity) {
mainActivity = activity;
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("xxx")) {
Log.i("show pop", "xx");
}
return false;
}
#Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
return super.shouldOverrideKeyEvent(view, event);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
}
}

Turn javascript on in android webview

hello i am new to android developing,
I want to set my javscript turn on in my android webview. I tried everything, but it doesn't work. My code below is my webview class. I hope someone can help me.
package visuals.Webview;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class VisualsActivity extends Activity {
/** Called when the activity is first created. */
final Activity activity = this;
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
// webview.setWebViewClient(new myWebClient());
webview.loadUrl("http://192.168.0.62/lastversion/index.php");
webview.getSettings().setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.getSettings().setUserAgentString(getString(R.string.user_agent_suffix));
}
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) {
if (url.startsWith("tel:")) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
return true;
} else if (url.startsWith("mailto:")) {
url = url.replaceFirst("mailto:", "");
url = url.trim();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text").putExtra(Intent.EXTRA_EMAIL, new String[]{url});
startActivity(i);
return true;
} else {
view.loadUrl(url);
return true;
}
}
}
// To handle "Back" key press event for WebView to go back to previous screen.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Thank you for helping
WebView webView;
webView.getSettings().setJavaScriptEnabled(true);
Pretty easy :)
webview.getSettings().setPluginState(PluginState.ON);
or when using older version ( < API 8)
webView.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
And if you want your webview's javascript to be able to interact with your android application. Take a look at webview's addJavascriptInterface method documentation.

Categories