#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    10
    Rep Power
    0

    Android Php web application


    Ok, so I am very new to android but I have some experience with PHP. I have a website for my college festival where there is a login system and registered users can take the quiz everything.( I am using Codeigniter as my PHP framework Now I have been asked to make an android app for the festival. So , my question is , How do I connect my android application to the stuff on my website.

    For example: I have a login system on my website and I want to reflect the same functionality in my android app i.e How to send the username and password to be authenticated and how the request will be processed on the server side? How do I connect my android application to my database ?

    Can anyone please point me in the right direction. Thank you very much.

    P.S : Yes, I get that I can very easily just make a mobile version of the website as suggested by many people. But since I want to learn Android, I think this would be a good opportunity for me to do so.

    <link removed>
    Last edited by E-Oreo; April 9th, 2013 at 09:08 PM.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Through HTTP requests.

    Setup a private web service API on your website.

    A web service API is simply another interface for your web application. It's not a user interface, as users (other humans) wont be using it. It's a programming interface, meaning other software applications will use it to talk to your app.

    A private web service API is simply the same as above, but with some sort of required authentication (to prevent other people using/abusing it), where only you (the dev) can use it.

    Less brief explanation of an API (Application Programming Interface):

    Currently, your web app has a user interface. This user interface is simply (and normally) the usage of HTML, which the users browser then renders and the user uses it (to do whatever on your site/web app).

    An API would/should not spit out HTML, as the response is not for the human eye. It should spit out JSON or maybe XML, as this is what most programming languages understand.

    A really really quick and lousy example of a web service API for fetching the current date, in PHP:

    PHP Code:
    <?php

    //get the current date
    $cDate date'd-m-y' );

    //we have the date, now we need to output it
    //because this is a web service API, we'll output the response in JSON
    //this will allow any other language (that supports (can understand) JSON) to be able to read the data from the response, appropriately.
    //PHP has built-in JSON support
    echo json_encode$cDate );
    If it was a user interface we were working on, we would not output JSON. Instead, we would output standard text (or HTML to make it look pretty).

    So if it was a user interface, we would have
    PHP Code:
    echo $cDate
    or to make it look nicer
    PHP Code:
    echo '<span style="blah blah">'.$cDate.'</span>'
    So once you have your web service API setup, you can come back to your Android app and start making HTTP requests. You can make POST and GET requests with Java.

    For more info on HTTP requests on Android, use Google or check this out: http://stackoverflow.com/questions/4...p-post-request.

IMN logo majestic logo threadwatch logo seochat tools logo