I have data to send to a web server, the server receives the strings following this pattern:
link {id} / {latitude} / {longitude}
How do I send this data by filling these spaces at once with Android studio?
I have data to send to a web server, the server receives the strings following this pattern:
link {id} / {latitude} / {longitude}
How do I send this data by filling these spaces at once with Android studio?
Simple:
String url = "http://teste.com/pagina?id=" + id + "&latitude=" + latitude + "&longitude=" + longitude;
After the server side:
$id = $_GET['id'];
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
This android developer page teaches you to do something similar using volley, but I would do this using POST instead of GET because of security issues, since it is sent by the url may have its data changed, more information w3schools.com page
I highly recommend using retrofit to consume APIs
interface TesteService{
@GET("{id}/{latitude}/{longitude}"
Call<Objeto> getObject(@Path("id") String id,
@Path("latitude") String latitude,
@Path("longitude") String longitude);
}
public class TesteRetrofit{
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://teste.com/")
.build();
TesteService tService = retrofit.create(TesteService.class);
public Objeto pegarObjeto(){
return tService.getObject("123","20°34'07.2\"S","43°48'44.6\"W").execute().body();
}
}
This is a basic example of code, I suggest you read about documentation to learn more.
This code will throw the I/O on UIThread
exception if run on the Android main Thread