Android http requests and javascript - android

I want to provide a better interface to a web browser game - dedicated to Android. The game uses javascript and a bit of flash (so simple that it appears in webview correctly). It has lots of images that make the page load for ages on my device.
My first idea was to make a webview GONE, but it doesn't solve my problem that page loads really long.
My second idea is to use something like HttpClient (any advices?) to get HTML code of site and then parse it (all data that I need is there). BUT here comes two troubles:
1) How can I handle cookies? Is it hard?
2) How can I execute javascript without a WebView?

It's easy to create HTTP(s) request. Take a look at HttpURLConnection class.
There is an exemple how to handle cookies.
Here you can find a quick introduction to the HttpURLConnection.
You won't be able to execute javascript. But if you are creating an app for you webapp you will need to recreate the behaviour. The javascript is useless with a native app.

Related

Headless Browser for Android?

After much frustration I need some help getting a HTML parser for Android.
I basically need a parser which will log into a website and retrieve the main page, which heavily uses javascript and ajax to render data. From there I need to be able to access other pages which are linked with anchor tags. Again, emphasis on the Ajax and javascript on the page, all the data is created through these means.
EDIT: After some research it looks like I need a headless browser that is compatible with Android.
At first I tried with JSoup and it only retrieves the page without the javascript and ajax data being written in. Unless I'm understanding something wrong here, JSoup is not fitting in this situation.
I have also tried HtmlUnit, which works perfectly, but I am unable to get it up and running in android because of the known jar conflicts and the "not being able to convert to dalivik" error.
If anyone knows another suitable HTML parser, or can help me with either getting JSoup and ajax pages to play nice, or knows how to get HtmlUnit running on android, I would be forever in your debt.
I have already spent the majority of a week with JSoup and HtmlUnit, and basically have gone back to square one. Frustration has set in and I'm completely lost on what to do.
Again, I need a HTML parser, that will allow Ajax and Javascript to load before I can parse, and it needs to be android friendly!
Thank you!
You can try to intercept the individual Ajax communications. They are either get or post communication. And you can call them with JSoup one by one. It is feasible for a handful of Ajax call. In fact there are less data and can be more quicker to parse on Android this way.

Create a Booklet like app in Phonegap

I am making a Book like app in Phonegap with Quiz... I want to keep 20 chapters for learning C. I am confused on how to use the single page architecture for such an app. I have also made a similar app for Android using JQuery Mobile and Android WebView before I was familiar with Phonegap but the application contained a number of (around 15 ) pages..and the Look & Feel was no more much native.
Any Suggestions on how to follow a single page architecture to create a book accessing its page contents from WebSQL for e.g. Chapter_title, page_heading, topic_contents ... and images if any.
Couple of months back I was in your situation. I experimented with jquery mobile, native application and phonegap. Building a web application at first seemed very attractive at first as the coding is a lot easier compared to native applications.Even though my answer is not very specific to your question it might be helpful to others. Here is my opinion based on my research:
Using phonegap slows your application responses, it loads slowly and together with jquery mobile the response and load time increases. So I didnot use it.
Using jquery alone was no different in Gingerbread mobile and on emulator you can clearly see the lag in switching between one div to another div. I didnot use it either.
What I did was android Webview. I wrote my own javascript and css and placed them on the section of my page. Used .... for changing pages on button click. This approach worked wonders for me and gave nearly native performance.
To follow the single page architecture in html use div element as I have mentioned in step 3 above. You can write a script to convert your WebSql data to json format. Then in your page where you need to call the data using javascript parse the data. Using json in really simple.

Create Android Client For Website

As a beginner wanting to become more familiar with the android platform, I wanted to create a web client for a website.
Something similar to https://play.google.com/store/apps/details?id=com.krinsen.javadocreader&hl=en
However, I am confused about how the author created the custom UI for the java docs.
To my understanding, there are 2 ways to do this.
One approach is with WebViews. I quickly prototyped a sample of this but I believe (correct me if I'm wrong) that I can't change the UI of the WebView and will have to view the page from the perspective of a browser. Unfortunately, this does not look very well as the website was not mobile optimized and there are inconsistent spacings and odd whitespace.
The second approach is to manually create each View using the different layouts provided by android (LinearLayout, TableLayout, etc). This should create a more custom mobile experience as I can manually construct how each page will look. However, this seems time-consuming as I will need to manually create a different UI page for each page of the website. Also I am confused as to how to pull the data from the website as each new view in the new UI will need the content from the website. Do I need to do HTML parsing to pull the content or is there a better way in the android sdk? What is a good approach that android developers take to extract the different forms of content from a website to redisplay on a android client?
Finally, since I have a very beginner understanding of this situation, am I correct in assuming that most likely the creator of the application mentioned above did something similar to the second approach I mentioned?
What is a good approach that android developers take to extract the different forms of content from a website to redisplay on a android client?
I think the best way is to provide an API for native application. Parsing HTML might look nice untill you need to suppport every change in your HTML page. But if you are not the owner of web-site there is no other choise if only you don't contact owners and ask for an API.

I want to make an app for android that updates via the internet so the information is always current. What is the best way to implement this?

I want to make an app for android that updates via the internet so the information in the app is always current. What is the best way to implement this?
I understand I will need the information stored somewhere?
And I will need to be able to access it and read it into the app?
I am not looking for specific code so much as a general way this could be implemented.
As an example think of a weather app that must pull weather data from an online source.
Thanks
In general you could achieve what you want in one of the following ways (both are popular methods and used in many apps):
Implement a web service layer to pull the data from the server back to your application. In Android, this is normally done via JSON based REST API. JSON is used nowadays as the data is regarded more compact that XML and it's easier to deal and manipulate in Android.
Note that it's common to implement caching in phone local storage if the data is not updated frequently.
Most of the time, the authoritative data is stored in the server
With this method, you could arrange the layout freely on your app. However, you need to write Java code to arrange the layout
You could also add better interactivity especially if you are thinking that your UI will have a lot of touch interfaces or animation
Other way you could do this is by developing a mobile HTML webpage that you could embed in Android via Webview. A simple tutorial is available on Android's website
This method will retrieve HTML from the server, the same way your desktop browser retrieves HTML. The only difference is that the HTML is mobile optimized. Good example of mobile optimized HTML is gMail from Google
Using this method, unless you have full control of the server side, you don't necessary can control the layout as the server is the one that generates the HTML
A lot of times that interactivity is reduced with this approach though Javascript framework such as Sencha and others are quickly reducing the interactivity gap between native code (#1) and using HTML

What's the best method for having an XSLT presentation layer in Android?

I'm fairly new to Android, but have done lots of Java/JSP development and HTML over the last 10 years. So I'm not real familiar with what Android can do. With this current project I'm working on, I'm going to have to read XML/XSLT files and display them in an Adroid application. However, there are a couple caveats:
1. The links in the page should be handled within my own app and not the default web browser (except external links)
2. The XSLT will be stored locally, with the XML retrieved online.
I don't want to waste hours trying to fit a square peg in a round hole if anyone has already done something like this and knows what to do.
Thanks.
Use a webview.
From the documentation:
A View that displays web pages. This class is the basis upon which
you can roll your own web browser or simply display some online
content within your Activity. It uses the WebKit rendering engine to
display web pages and includes methods to navigate forward and
backward through a history, zoom in and out, perform text searches and
more.
It will render your html like the browser, but you have plenty of ways to control its behavior and the presentation of it in your app.
It is very easy to get started with, a good start is the google Hello, WebView tutorial

Categories

Resources