Hi i've been searching a lot but couldn't find anything that could help.
I am creating an android app for our existing website. The website itself will load, but the main form where users can sign in won't load. Does anyone have any idea how this happens?
The website is https://app.one-2-ten.com/v2
p.s. This is the first time I am making an android app so sorry if its an obvious solution.
ProgressBar progressBar;
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView = (WebView) findViewById(R.id.webView);
if (savedInstanceState != null) {
webView.restoreState(savedInstanceState);
}
else{
webView.getSettings() .setJavaScriptEnabled(true);
webView.getSettings() .setSupportZoom(false);
webView.getSettings() .setBuiltInZoomControls(false);
webView.getSettings() .setLoadWithOverviewMode(true);
webView.getSettings() .setUseWideViewPort(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setWebViewClient(new ourViewClient());
webView.Settings.AllowContentAccess = true;
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged (WebView view, int progress){
progressBar.setProgress(progress);
if(progress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
progressBar.setVisibility(ProgressBar.VISIBLE);
}if(progress == 100){
progressBar.setVisibility(ProgressBar.GONE);
}
}
}
);}
String data = getIntent() .getDataString();
if(Intent.ACTION_VIEW.equals(getIntent() .getAction())){
webView.loadUrl(data);
}else{
webView.loadUrl("https://one2ten-system.parseapp.com/v2");
}
}
public class ourViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
if (url.contains("one2ten-system.parseapp.com/v2")) {
v.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
} else {
Uri uri = Uri.parse(url);
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
}
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
}
#Override
public void onBackPressed() {
if(webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
#Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
webView.saveState(outState);
}
}
I've found what my issue was, I forgot to add the following line: webView.getSettings().setDomStorageEnabled(true);
This enables the browser to store user data from forms for example, which it needs because you land on a login page.
If my answer is incomplete please let me know!
Thanks
Related
I have created a webview app of my site in Android Studio. Could someone please look into the code and solve the issue. This is my code:
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url == null || url.startsWith("http://") || url.startsWith("https://")) return false;
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} catch (Exception e) {
return true;
}
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("https://xyz.in/admin_login.php");
}
public void onBackPressed(){
if(webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
When WhatsApp icon is clicked, it's opening in WhatsApp application,but when view location is clicked, the button is not responding. Please help on this issue.
Please find the attached image for your reference
It opens my link in Webview but when I try to open hyperlinks and content of the web or navigation link, it starts opening with the default browser.
public class MainActivity extends Activity {
private WebView mWebView;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://");
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Objects.requireNonNull(Uri.parse(url).getHost()).endsWith("http://www.ieltsmadeeasy.tk/")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
}
I want to browse the whole website inside the web view, not any browser please help me
Here is some documentation about WebViews: https://developer.android.com/guide/webapps/webview#java
The problem is, that you don't override the shouldOverrideUrlLoading(view, url) function of the WebViewClient, as you use the default one.
If you use this as the WebViewClient, it should work (copied from examples in documentation):
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("https://www.example.com")) {
// This is my website, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
So, just take this class and change the line mWebView.setWebViewClient(new WebViewClient()); to mWebView.setWebViewClient(new MyWebViewClient());
Hi I have totally no idea why my webview is not call the onPageFinished method, and the it was showing the loading dialog all the time, I hope there is someone out there help me for my this issue. In the Android manifest file I already put the internet permission and also the network access state.
so this is my code:
public class MainActivity extends AppCompatActivity {
WebView mWebView;
RelativeLayout rLoading;
Map<String, String> header;
String urlToLoad;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
rLoading = (RelativeLayout) findViewById(R.id.loading);
if ( isNetworkAvailable() == true ) //check if internet available or not
{
mWebView.setFocusable(true);
mWebView.setFocusableInTouchMode(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
urlToLoad = "https://www.google.com/";
UsernamePasswordCredentials creds= new UsernamePasswordCredentials("username", "password");
Header credHeader = BasicScheme.authenticate(creds, "UTF-8", true);
header = new HashMap<String, String>();
header.put(credHeader.getName(), credHeader.getValue());
//show loading dialog
mWebView.loadUrl(urlToLoad, header);
mWebView.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url) {
rLoading.setVisibility(View.GONE);
}
});
}
else //Not connected
{
Toast.makeText(
this,
"No internet connection",
Toast.LENGTH_LONG
).show();
}
}
public boolean isNetworkAvailable() {
ConnectivityManager connectivityMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityMgr.getActiveNetworkInfo();
/// if no network is available networkInfo will be null
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()){
mWebView.goBack();
}else {
super.onBackPressed();
}
}
}
Someone please help me
Try this Android WebView implementation:
webview= (WebView) findViewById(R.id.webview);
webview.loadUrl("www.google.com");
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//stop the ProgressBar
mProgressBar.setVisibility(View.INVISIBLE);
}
});
You can do it by this way
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap facIcon) {
//SHOW LOADING IF IT ISNT ALREADY VISIBLE
}
#Override
public void onPageFinished(WebView view, String url) {
progressDialog.dismiss();
}
});
I programmed an app which opens a WebView via Imagebutton. If there is no Internet and the app is started a little popup comes up which says "No Internet". If i started the app with Internet and i lost the Internet during using the WebView a very ugly Screen shows up with error. How can i prevent my Webview loading a new side if there is no Internet, a small Toast should open or Textfield with "Sorry you lost your Connection :/", thanks!
Here my Code
public static boolean checkInternetConnection(Context context) {
ConnectivityManager con_manager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (con_manager.getActiveNetworkInfo() != null
&& con_manager.getActiveNetworkInfo().isAvailable()
&& con_manager.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
private ImageButton Ilias_link;
private ImageButton Lsf_link;
private WebView mWebView;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
if (!MainActivity.checkInternetConnection(this)) {
Toast.makeText(getApplicationContext(), "Du hast leider kein Internet", Toast.LENGTH_SHORT).show();
} else {
Ilias_link = (ImageButton) findViewById(R.id.ilias_link);
mWebView = new WebView(this);
Ilias_link.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.getSettings().setSupportZoom(true);
if (savedInstanceState == null)
mWebView.loadUrl("https://elearns02.fh-biberach.de/ilias3/login.php?target=&soap_pw=&ext_uid=&cookies=nocookies&client_id=HSBC&lang=de");
mWebView.setWebViewClient(new WebViewClient());
setContentView(mWebView);}
});
Lsf_link = (ImageButton) findViewById(R.id.lsf_link);
mWebView = new WebView(this);
Lsf_link.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.getSettings().setSupportZoom(true);
if (savedInstanceState == null)
mWebView.loadUrl("https://lsf.fh-biberach.de/qisserver/rds?state=user&type=0");
mWebView.setWebViewClient(new WebViewClient());
setContentView(mWebView);{
}};
})
;}
ImageButton imageButton = (ImageButton)findViewById((R.id.Mensaplan));
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Comming soon ;)",Toast.LENGTH_LONG).show();
}
});}
public void onPageFinished(WebView view, String url) {
String javascript="javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'initial-scale=1.0,maximum-scale=10.0');";
view.loadUrl(javascript);
}
#Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
mWebView.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
mWebView.restoreState(savedInstanceState);
}
private static final int TIME_INTERVAL = 3000;
private long mBackPressed;
#Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
return;
} else
{ if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis())
{
super.onBackPressed();
return;
}
else { Toast.makeText(getBaseContext(), "Tap back button in order to exit", Toast.LENGTH_SHORT).show(); }
mBackPressed = System.currentTimeMillis();
}
}
}
Try doing this -
May be it will work. I made a project and used this.
DetectConnection.java
public class DetectConnection {
public static boolean checkInternetConnection(Context context) {
ConnectivityManager con_manager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (con_manager.getActiveNetworkInfo() != null
&& con_manager.getActiveNetworkInfo().isAvailable()
&& con_manager.getActiveNetworkInfo().isConnected()) {
return true;
} else {
return false;
}
}
}
The main code will be :-
if (!DetectConnection.checkInternetConnection(this)) {
Toast.makeText(getApplicationContext(), "No Internet!", Toast.LENGTH_SHORT).show();
} else {
wv = (WebView) findViewById(R.id.donate_webView1);
c = new CustomWebViewClient();
wv.setWebViewClient(c);
wv.clearCache(true);
wv.clearHistory();
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl("http://www.google.com");
}
// Function to load all URLs in same webview
private class CustomWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!DetectConnection.checkInternetConnection(this)) {
Toast.makeText(getApplicationContext(), "No Internet!",Toast.LENGTH_SHORT).show();
} else {
view.loadUrl(url);
}
return true;
}
}
I hope it works :)
im trying to make an webview application for android with progress bar, i tried a lot of examples from here but none was working .. my problem is that on a frame page or a page with facebook likes or comment plugin the progressdialog never stoped .. here is my code.. please test it and tell me what is wrong.
private WebView webview;
private ProgressDialog progressDialog;
boolean loadingFinished = true;
boolean redirect = false;
int nr = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.string.webview);
final Activity activity = this;
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
webview.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setTitle("PitziWorld");
progressDialog.setMessage(progressDialog.toString());
progressDialog.setCancelable(isFinishing());
progressDialog.show();
}
loadingFinished = false;
}
public void onPageFinished(WebView view, String url) {
if(!redirect){
loadingFinished = true;
}
if(loadingFinished && !redirect){
if (progressDialog.isShowing() || progressDialog!=null) {
progressDialog.hide();
progressDialog = null;
}
} else{
redirect = false;
}
}
});
webview.loadUrl("http://www.pitziworld.ro");
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
WebView webView = (WebView) findViewById(R.string.webview);
//Verifica daca tasta apasata a fost back si daca exista istoric
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// Daca nu a fost tasta back sau nu este istoric, returnam valoare buton
`
this is what you are looking for!
public void onPageStarted(WebView view, String url, Bitmap favicon) {
mProgress.show();
}
to load progress bar in every page
this is it!