Reputation: 391
I have 2 problem was the interia dawn to solve, I'm trying to load a site within the webview my android application, the site works coprretamente within the webview it opens normally there starts coming problems
This site has a registration form and when the registration ends it redirects to another page within the same domain ...
The Webview is not redirecting after clicking the register button and terminanar registration, it appears the warning that the registration was successful but does not redirect.
This creates the second problem, I need to get the link that was redirected to check if it contains the word "finalcadast" if you need this word that the app redirects me to my main application view.
Can someone help me ? already thank you very much.
Here's the code of my activity webview
public class cadastro extends AppCompatActivity {
private WebView wv;
private String urlEmCurso;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastro);
wv = (WebView) findViewById(R.id.webView_cadastro);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
//settings.setBuiltInZoomControls(true);
//settings.setSupportZoom(true);
wv.requestFocusFromTouch();
wv.setWebChromeClient(new WebChromeClient());
//Isso desabilita o Toolbar nativo do WebView
progressDialog = ProgressDialog.show(this, "", "Carregando formulário de cadastro , aguarde...");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlinterna) {
//urlinterna = "https://onneti.net/melleven/cad.html";
Log.i("URL", "getUrl: " + view.getUrl());
Log.i("URL", urlinterna);
urlEmCurso = urlinterna;
//Para redirecionar para Activity de cadastro
if (urlEmCurso.contains("noSession")) {
Intent intent = new Intent(getApplication(), MainActivity.class);
//intent.putExtra("url", urlEmCurso);
startActivity(intent);
}
progressDialog.show();
wv.loadUrl(urlinterna);
return false;
}
@Override
public void onPageFinished(WebView view, String url){
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
}
});
wv.loadUrl("https://onneti.net/melleven/cad.html");
}
}
Here is the code of my web page that redirects, the computer works normally but the webview does not work.
$.ajax({
type : 'POST',
data : formula,
url : 'https://onneti.net/melleve/j.php',
success : function(data){
if(data == '' || data == 0){
alert('Cadastro realizado com sucesso');
location.replace("https://onneti.net/melleve/finalcad.html?cadastro=finalcadast")
//$state.go('app.lg');
}
if(data == 1){
alert('E-mail já cadastro, por favor escolha outro e-mail ou se esqueceu sua senha clique em "ESQUECI MINHA SENHA"');
}
}
})
Upvotes: 0
Views: 4714
Reputation: 58
Try Like this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastro);
wv = (WebView) findViewById(R.id.webView_cadastro);
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
wv.requestFocusFromTouch();
wv.setWebChromeClient(new WebChromeClient());
wv.loadUrl("https://onneti.net/melleven/cad.html");
progressDialog = ProgressDialog.show(this, "", "Carregando formulário de cadastro , aguarde...");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String urlinterna) {
urlEmCurso = urlinterna;
if (urlEmCurso.contains("noSession")) {
finish();
startActivity(getIntent());
}
else {view.loadUrl(url); // Stay within this webview and load url
return true;}}});
}
@Override
public void onPageFinished(WebView view, String url){
if(progressDialog.isShowing()){
progressDialog.dismiss();
}
super.onPageFinished(view, url);
}
});
}
Upvotes: 1