Retouch the App screen - Android Cordova

Asked

Viewed 749 times

0

I’m developing an app for Android using Cordova, on my login screen, I send the data to a file in my domain, it makes the request takes the data, now, how to go back to the app screen to confirm the data, IE, it will do the requisicao in a file that is in the air, and return to the app...

1 answer

1


You can solve this problem in many ways.

The first step is to understand what you really need, if you only need the data to validate the user login you can use JSONP, making a simple request with the form data. Use Javascript to get the values of Inputs. You can also use a simple HTML return. To access this data you can use jQuery. Using jQuery you can use the get and password.

$.get( "dominio.com.br/login.php?usuario=" + usuario + "&senha=" + senha, function(dados) {
  // Executa algum código com o resultado
});

With this it is possible to login and get the information easily. It is also possible to use POST.

It should be made clear that JSON or even with JSONP when making data requests through Javascript you may encounter errors regarding Crossdomain, as your application does not have the same domain of content that is being accessed, Webkit tries to block this access. Search about Cross Domain, JSONP and CORS for a better understanding of the subject.

If you really need to open the browser of Smarthphone to do some kind of authentication as the account of Twitter or Google you can create a window and store it in a variable, Javascript can only close windows that it has opened. This way you just open the window, store in a variable and when the authentication is ok you simply close the window.

The example below makes this clear, a window is opened and stored in a variable, then a listener is created for the event loadstop, this listener defines that after 5 seconds the window must be closed. In your case check if the authentication system supports a callback function or if it emits an event when authenticated, in this case you do not need to close after receiving the full load event, you can close only when you receive the correct event.

   var win = window.open( "http://docs.kendoui.com", "_blank", "EnableViewPortScale=yes" );
    win.addEventListener( "loadstop", function() {
        setTimeout(function() {
            win.close();
        }, 5000 );
    });

Links that can help:

Cross Window Communication With Cordova’s Inappbrowser

So, JSONP or CORS?

jQuery.get()

Jquery Cross Domain Ajax

Browser other questions tagged

You are not signed in. Login or sign up in order to post.