Good night now in the webview that I am working I have the following problem, when I log in via facebook on the site encapsulated by the webview I am redirected to the login page of the face I fill in my data and click on login, it authenticates and returns to the webview site, but for some reason it reloads the site again and gets in an infinite loop, what do I do ?, I'll leave my codes below.
activy_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/pb"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="15dp"
android:max="100"
android:progress="5" />
<WebView
android:id="@+id/WebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" >
</WebView>
</LinearLayout>
MainActivity.java:
package br.com.fradeilha.www.supermercadofrade;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private static final String target_url="https://www.sitemercado.com.br/frade";
private WebView mWebView;
private ProgressBar pb;
public static boolean isConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork && activeNetwork.isConnectedOrConnecting()) {
return true;
} else {
return false;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (findViewById(R.id.pb));
mWebView = (findViewById(R.id.WebView));
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
mWebView.loadUrl(target_url);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setSupportMultipleWindows(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Intent i = new Intent(MainActivity.this, off.class);
startActivity(i);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
});
pb.setProgress(0);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int Progress) {
pb.setProgress(Progress);
if (Progress == 100) {
pb.setVisibility(view.GONE);
} else {
pb.setVisibility(view.VISIBLE);
}
super.onProgressChanged(view, Progress);
}
});
if (isConnected(getApplicationContext())){
} else {
Intent i = new Intent(MainActivity.this, off.class);
startActivity(i);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
}
public void onBackPressed() {
if (this.mWebView.canGoBack()) {
this.mWebView.goBack();
} else {
this.finish();
}
}
}
It seems like something is missing from the webview, the chrome browser works normally.