Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Integrating javascript into an android app

Options
  • 24-06-2013 11:04am
    #1
    Registered Users Posts: 8,018 ✭✭✭


    I'm fairly new to Android development but I'm getting along pretty good with it so far. I'm stuck now with trying to integrate javascript into my app? There is this page which has 2 javascript elements, calendar and map, it takes input from a list of counties as well.

    What I want to do is somehow integrate both these javascript elements into my app. I know about webview but in its basic form it is just a web link that opens a browser? I was also looking addjavascriptinterface but I don't really understand if this is what I need to be using? How do I reference the javascript elements and how do I pass a parameter to the javascript like the web page is doing?


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    What I want to do is somehow integrate both these javascript elements into my app. I know about webview but in its basic form it is just a web link that opens a browser? I was also looking addjavascriptinterface but I don't really understand if this is what I need to be using? How do I reference the javascript elements and how do I pass a parameter to the javascript like the web page is doing?
    It's very difficult to ascertain what you're trying to do, but I'll give it a shot.

    I presume you're essentially just using the app as a wrapper around your HTML page, which will act as your de-facto UI? If not, doing it like this may not be the best approach.

    If so, essentially all you need do is just let the browser execute the JavaScript as if it would on any other page in the Browser. If you need to pass parameters from your app to your Web page, you can send them as GET parameters in the loadUrl method.


  • Registered Users Posts: 8,018 ✭✭✭youcancallmeal


    It's very difficult to ascertain what you're trying to do, but I'll give it a shot.

    I presume you're essentially just using the app as a wrapper around your HTML page, which will act as your de-facto UI? If not, doing it like this may not be the best approach.

    If so, essentially all you need do is just let the browser execute the JavaScript as if it would on any other page in the Browser. If you need to pass parameters from your app to your Web page, you can send them as GET parameters in the loadUrl method.

    Yeah sorry I'm finding it hard to explain, I don't know a lot about javascript either which doesn't help. What I want to do is display only the javascript part of the HTML page using my app as the wrapper/ui? The reason I want to do this is because ultimately I want the user to be able to use the details returned by the javascript as a basis for creating a new calendar entry on their android device?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    I presume you're screen scraping?


  • Registered Users Posts: 8,018 ✭✭✭youcancallmeal


    I presume you're screen scraping?

    I have experience with screen scraping using jsoup but my understanding is that you can't scrape javascript the way you would HTML?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    I have experience with screen scraping using jsoup but my understanding is that you can't scrape javascript the way you would HTML?
    Yes, not least of all because one is a mark-up language used for formatting and the other is executable code - however, for what you're trying to do it's irrelevant.

    Basically, how you're trying to do this is all arseways; even if you could do it, it would be horrifically complex and you'd end up with all sorts of problems, not least of all maintenance.

    My advice is forget about this approach. Keep the UI native and just scrape the data that is returned when the county data is sent back to the server via POST, then use that to populate whatever calendar you code natively.


  • Advertisement
  • Registered Users Posts: 8,018 ✭✭✭youcancallmeal


    My advice is forget about this approach. Keep the UI native and just scrape the data that is returned when the county data is sent back to the server via POST, then use that to populate whatever calendar you code natively.

    Interesting, I think I get what you mean. So display the page in a webview then when the user has selected an option to populate the calendar I scrape it and use the returned data whatever way I want? The page the user will be looking at is not optimised for mobile but I don't really have much choice I suppose?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Interesting, I think I get what you mean. So display the page in a webview then when the user has selected an option to populate the calendar I scrape it and use the returned data whatever way I want? The page the user will be looking at is not optimised for mobile but I don't really have much choice I suppose?
    No. Just emulate using sockets, whatever transaction is taking place via the Web page; there's a HTTP POST, with a response that appears to be returning data taking place - probably more to it than that, but that's for you to figure out.

    Then display your data normally using the native UI, not a WebView.

    A variation on this would be to harvest the data and put it on another server in an straight-forward XML or json format, and have the app just pull that.


  • Registered Users Posts: 8,018 ✭✭✭youcancallmeal


    No. Just emulate using sockets, whatever transaction is taking place via the Web page; there's a HTTP POST, with a response that appears to be returning data taking place - probably more to it than that, but that's for you to figure out.

    Sorry you lost me here, tried googling 'android emulate sockets' and what I think you mean is that I can make a call the server where the javascript resides and have the HTML result returned that I can scrape?


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Sorry you lost me here, tried googling 'android emulate sockets' and what I think you mean is that I can make a call the server where the javascript resides and have the HTML result returned that I can scrape?
    I said emulate the transaction that the browser is making, using Sockets - or HttpURLConnection, or HttpClient - there's clearly a HTTP POST taking place and what comes back is the calendar all filled out.

    Honestly, I've not looked too deeply at what's going on under the surface, but from what I can see, there's not a Hell of a lot of JavaScripting going on there; seems to be just HTML.

    So scrape that and then format it using a native Android layout.


  • Registered Users Posts: 8,018 ✭✭✭youcancallmeal


    I said emulate the transaction that the browser is making, using Sockets - or HttpURLConnection, or HttpClient - there's clearly a HTTP POST taking place and what comes back is the calendar all filled out.

    Honestly, I've not looked too deeply at what's going on under the surface, but from what I can see, there's not a Hell of a lot of JavaScripting going on there; seems to be just HTML.

    So scrape that and then format it using a native Android layout.

    Okay I'll give that a shot and report back. Thanks very much for your help


  • Advertisement
Advertisement