Хочу отправить на свой сервер данне о широте и долготе через http но выдает ошибку в манифесте разрешение на использование интерента запросил
Ошибка - E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.drivein, PID: 5716
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:185)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:172)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:130)
at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1317)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:707)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:696)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:519)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:497)
at com.example.drivein.MainActivity.formatLocation(MainActivity.java:130)
at com.example.drivein.MainActivity.showLocation(MainActivity.java:113)
at com.example.drivein.MainActivity.access$000(MainActivity.java:34)
at com.example.drivein.MainActivity$1.onLocationChanged(MainActivity.java:82)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:281)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:210)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:226)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
I/Process: Sending signal. PID: 5716 SIG: 9
код
private String formatLocation(Location location) {
if (location == null)
return "";
String a, b, answerHTTP;
a = ((Double) location.getLatitude()).toString();
b = ((Double) location.getLatitude()).toString();
String server = "http://demo.harrix.org/demo0011";
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(server + "?a=" + a + "&b=" + b);
try {
HttpResponse response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
answerHTTP = EntityUtils.toString(entity);
}
}
catch (ClientProtocolException e) {
}
catch (IOException e) {
}
return String.format(
"Coordinates: lat = %1$.4f, lon = %2$.4f, time = %3$tF %3$tT",
location.getLatitude(), location.getLongitude(), new Date(
location.getTime()));}