3

I've been researching networking in android and have become familiar with the basic concepts. However, I've recently been working on an app intended for use by my school as a gradebook/assignment display of sorts. My school uses the following online gradebook: https://parents.mtsd.k12.nj.us/, and currently I'm trying to allow students to input their login credentials into my app which will then try to retrieve their respective information and display it in a gridview. However, I have never attempted to log in to a website from an android app before parsing data (I have gone through several similar questions but I am still a little confused)

Any help is appreciated!

[edit] After logging in I will use import.io to display gradebook data, website does not have api

mlz7
  • 1,697
  • 3
  • 20
  • 48
  • I'm assuming they don't have an API, so I'd use the `JSoup` library. It can log in, retrieve the cookies, and you can then easily parse the data. After that you can just put it in a `GridView`. – Victor Santiago Jul 24 '15 at 01:26
  • There is a link [here](http://www.mkyong.com/java/how-to-automate-login-a-website-java-example/) which might answer your question. – Leo Jul 24 '15 at 03:02

2 Answers2

1

If I understand You clearly u need to :

  1. Connect to site using HttpURLConnection with user creditentials (do Post request to login page)
  2. Obtain cookies from request (my favorite way is to parse - copy appropriate header field)
  3. Use obtained cookies with HttpURLConnection.setRequestProperty("Cookie",obtainedCookies) and do another request(to user data page).
  4. Get input stream
  5. Parse stream (to obtain Document "html" u can use jsoup example: Document doc = JSoup.parse(stream, null, "");

  6. Show data

GUIDELINES:

cookie how to

Most useful example

Caution:

-any http requests needs to be done outside main thread (ui thread) - u can use async task for this or intent service

EDIT on questions:

you ask whether to use Jsoup to handle connection?

my answer is NO!

Jsoup is a PARSER by using HttpURLConnection u gain full control over HTTP request so for example u can handle some specyfic exceptions or request propertiers which jsoup is not capable! from my experience after a while I start to disassemble the libraries and learn from them the basics and use parts of them in my code!

Community
  • 1
  • 1
ceph3us
  • 6,591
  • 2
  • 34
  • 39
  • would you recommend using HttpUrlConnection rather than JSoup throughout? – mlz7 Jul 25 '15 at 06:54
  • Thanks a lot! I have not done much networking previous to this so I wrote some code in Java to practice before adding it to android, but I still don't really understand the concept of submitting and taking data programmatically...My code is here: http://bit.ly/1D1MHWy – mlz7 Jul 25 '15 at 19:22
  • in hurry for u -> this way http://stackoverflow.com/questions/31629938/need-help-logging-into-website-and-retrieving-information/31630379#31630379 if u will have other question i can answer it later now im going out :D – ceph3us Jul 25 '15 at 19:36
0

You could make a WebView with a custom HTML file which has a login and password field, and then have the HTML file run the same script as the website to log them in.

Leo
  • 79
  • 4
  • Trying not to resort to WebViews and instead just have them input credentials locally and have the app log them in through the background thread – mlz7 Jul 24 '15 at 05:07