Search code examples
androidappcelerator

How to access querystrings from URL in android using appcelerator


I am implementing OAUTH in android using appcelerator. login page is redirecting to response page with token appended to query string e.g. http://mysite.com?access_token="token"

So I need to fetch this query string using appcelerator.

I have used Ti.App.getArguments() but this api is only working for ios not for android.

Is there any api available for fetching query string in appcelerator that works in android??


Solution

  • Add an event listener to the webview like so:

    webview.addEventListener('load', function(e){
        var url = e.url.split('?');
        var urlParams = url[1];
    });
    

    The variable urlParams will contain a string that looks like param1=value1&param2=value2 so from there you just need to split them up and find the access_token param.