0

I'm new in java / android, since I schedule for IOS and I'm with a doubt to send parameters to a function in PHP

well, is a form, when the User clicks on send, I save the contents of the form in strings.

have strings 4 at the end

name email nameUser EmailUser

I need to send them to function in php, I followed this tutorial:

but my problem is to have the value of strings as parameter to the function

In the IOS did the following:

....

NSString *urlEnvio = [[NSString alloc] initWithFormat:@"http://www.xxxx.com.br/indicar.php?destinatario=%@&remetente=%@&nomedestinatario=%@&nome=%@&enviar=%@", destinatario, remetente, nome,nomeRemetente, check];

...

is something I need java.

As requested, I edited the post .....

@Override
            public void onClick(View v) {
                String nome = seuNome.getText().toString();
                String email = seuEmail.getText().toString();
                String strNomeAmigo = nomeAmigo.getText().toString();
                String strEmailAmigo = emailAmigo.getText().toString();

                //chama funcao que envia
                indicar();

            }
        });
    }

    public void indicar(){
          new Thread(new Runnable() {
                public void run() {
                    BufferedReader in = null;
                    try {
                        HttpClient client = new DefaultHttpClient();
                        HttpGet request = new HttpGet();
                        request.setURI(new URI("http://www.xxxx.com.br/indicar.php?"));
                        //send to this address with the parameters: name, email, strNomeAmigo, strEmailAmigo
                        //

                        HttpResponse response = client.execute(request);
                        in = new BufferedReader
                        (new InputStreamReader(response.getEntity().getContent()));
                        StringBuffer sb = new StringBuffer("");
                        String line = "";
                        String NL = System.getProperty("line.separator");
                        while ((line = in.readLine()) != null) {
                            sb.append(line + NL);
                        }
                        in.close();
                        String page = sb.toString();
                        System.out.println(page);
                        } finally {
                        if (in != null) {
                            try {
                                in.close();
                                } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }

                }
            }).start();


    }

....

send to this address with the parameters: name, email, strNomeAmigo, strEmailAmigo

something like this: http://www.xxxxx.com.br/indicar.php?nome=name_example&email=example@example.com......

jucajl
  • 1,195
  • 3
  • 12
  • 29
  • 3
    This question is completely unreadable, and doesn't have any indication that you tried anything yet. – Falmarri May 02 '12 at 19:10
  • I did exactly what is the link for the tutorial, only difference is that I want to send strings as parameter to my PHP function. – jucajl May 02 '12 at 19:13
  • I pretty much agree with Flamarri but ill gladly try to help if you explain yourself better .. I do android-php communication all the time. do you want to use json or plain text , GET or POST , did you tried something without success? if you did then what did you try? – Joe May 02 '12 at 19:15
  • I edited the post, take a look – jucajl May 02 '12 at 19:23

2 Answers2

1

Your problem is encoding a url with your parameters, right? If so, you can use String.format for this. This How do I encode URI parameter values? SO question also address the same problem.

Community
  • 1
  • 1
renam.antunes
  • 761
  • 1
  • 5
  • 11
0

There are a number of ways to concatenate a string in Java. One way to format a string is with String.format:

String urlEnvio = String.format("http://www.xxxx.com.br/indicar.php?destinatario=%s&remetente=%s&nomedestinatario=%s&nome=%s&enviar=%s", destinatario, remetente, nome, nomeRemetente, check);

I prefer to use something that validates and properly escapes parameters though, so I prefer Uri.Builder.

jucajl
  • 1,195
  • 3
  • 12
  • 29
kabuko
  • 36,028
  • 10
  • 80
  • 93