1. Download our Official Android App: Forums for Android!

Apps how to submit

Discussion in 'Android Development' started by ezekel, Jan 18, 2014.

  1. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    Hi,

    I have 2 EditText Field, how can i pass my data to my server in localhost when the button is click,I already know how to use button click,but the problem is i don't know how to pass the value.?

    by the way in my php script when the data is pass by the android is it the same way in checking the parameters by using iset() ?.


    Thank you in advance.
     

    Advertisement

  2. Rukbat

    Rukbat Android Expert
    Rank:
    None
    Points:
    843
    Posts:
    10,392
    Joined:
    Jan 16, 2012

    Jan 16, 2012
    10,392
    2,894
    843
    Male
    Being retired and writing Tasker tasks.
    Fayetteville, NC, USA
    Pass by $_GET or $_POST, the same as any wen interface. isset() will work the same way, no matter what passes the variables.
     
    ezekel likes this.
  3. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    Hi Rukbat,

    THank you for the quick reply...can i ask how can i connect to my localhost so that i can pass my data to the localhost...what APi of org.apatche that i will use?

    THank you in advance.
     
  4. surlac

    surlac Newbie
    Rank:
    None
    Points:
    16
    Posts:
    25
    Joined:
    Jun 17, 2012

    Jun 17, 2012
    25
    4
    16
    Male
    Try something like the one below. It will open HTTP connection to localhost (provide exact URL to your php script) and send POST request along with "your_data" string:
    Code (Text):
    1. HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1").openConnection();
    2. con.setDoOutput(true);
    3. con.setRequestMethod("POST");
    4. OutputStream reqStream = con.getOutputStream();
    5. reqStream.write("your_data".getBytes());
     
    ezekel likes this.
  5. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    Hi surlac,

    Thank you for the reply...I am confuse for this "reqStream.write("your_data".getBytes());" what is the format of "your_data"?...you mean like this,...reqStream.write("name:mytestname".getBytes());..?

    please correct me if i am wrong.

    Thank you.
     
  6. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35

    By the way is it possible to return message back to my android phone then show some toast ?example message...success or invalid username and password..something like that.


    Thank you in advance.
     
  7. surlac

    surlac Newbie
    Rank:
    None
    Points:
    16
    Posts:
    25
    Joined:
    Jun 17, 2012

    Jun 17, 2012
    25
    4
    16
    Male
    "your_data" is a Serializable object, which you're able to reconstruct on the server. Default platform charset will be used in case of String.
     
    ezekel likes this.
  8. surlac

    surlac Newbie
    Rank:
    None
    Points:
    16
    Posts:
    25
    Joined:
    Jun 17, 2012

    Jun 17, 2012
    25
    4
    16
    Male
    Sure. Socket is still open, listen to the response like this:

    Code (Text):
    1. InputStream resStream = con.getInputStream();
    2. int len = resStream.read(byteBuf);
     
    ezekel likes this.
  9. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    @Surlac, Thanks i give a try on this.
     
  10. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35

    Hi surlac!, I could not get the idea of "serializable object" ...


    reqStream.write("fname:myfirsttextfield,pwd:mysecondtextfield".getBytes());..is this what you mean?

    please correct me if i am wrong.

    Thank you.
     
  11. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    I have error in logcat

    Error opening trace file: No such file or directory (2)

    this is the url HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1/mytest/login.php").openConnection();


    please i need your help.

    Thank you in advance.
     
  12. ezekel

    ezekel Newbie
    Thread Starter
    Rank:
    None
    Points:
    35
    Posts:
    18
    Joined:
    Jan 13, 2014

    Jan 13, 2014
    18
    0
    35
    Hi, Anyone help me on this thread please
     

Share This Page

Loading...