hi,
i am a student, and  developp a application on android for my project in
school.I use android release 1.1 and the android emulator.I would to use the
socket  in my application.I have use the package java.net.socket and
java.iobut i don't have a success.My code is below.Please help me.I
don't know how
i can solve the problem.I have explored  the package org.apache.http but i
don't know how i can use this package.
For the application, i want to send the data at android emulator for a
server web which is on another pc.Then the emulator android is a client.In
addition, i want to use the GPRS
192.168.1.6 is the ip address for the server web
3000 is a port that server listen to retrieve the data which are sended by
the emulator android

*

public* *class* androidtracabilite *extends* Activity

{

/** Called when the activity is first created. */

*private* LocationManager locationManager;

*private* LocationProvider *locationprovider*;

*private* Miseajour miseajour;

*private* Socket socket;

 *public* androidtracabilite()

{

miseajour = *new* Miseajour();

*try
*

{

socket=*new* Socket("192.168.1.6",3000);

}*catch*(Exception e)

{

//*sb*.append("Exception *levée*");

}

}

@Override

*public* *void* onCreate(Bundle tracabilite)

{

*super*.onCreate(tracabilite);

setContentView(R.layout.*main*);

String location_context = Context.*LOCATION_SERVICE*;

locationManager =(LocationManager)getSystemService(location_context);

testProviders();

*try*{

envoiesocket();

}

*catch*(Exception e)

{

System.*out*.println("Non effectué");

}

}

*public* Location testProviders()

{

Location location=*new* Location("mobil");

TextView tv = (TextView)findViewById(R.id.*myTextView*);

StringBuilder sb = *new* StringBuilder("Enabled Providers:");

List <String> providers= *new* ArrayList<String>(10);

providers =(ArrayList<String>)locationManager.getProviders(*true*);

*for* (String provider : providers)

{

locationManager.requestLocationUpdates(provider,0,0,miseajour);

location=locationManager.getLastKnownLocation(provider);

sb.append("\n\n").append(provider).append(" : ");

*if* (location != *null*)

{

*double* lat = location.getLatitude();

*double* lng = location.getLongitude();

sb.append(lat).append(" ; ").append(lng);

}

*else* {

sb.append("No location");

}

}

tv.setText(sb);

*return*(location);

}//fin *de* *la* *fonction* *testprovider
*

*public* *void* envoiesocket() *throws* Exception

{

System.*out*.println("Entrer dans la fonction");

TextView tv = (TextView)findViewById(R.id.*myTextView*);

StringBuilder sb = *new* StringBuilder("Envoie Socket");

 BufferedReader plec = *new* BufferedReader(*new* InputStreamReader(socket
.getInputStream()));

PrintWriter pred = *new* PrintWriter(*new*
BufferedWriter(*new*OutputStreamWriter(
socket.getOutputStream())),*true*);

pred.println("envoie de socket");

String read= plec.readLine();

plec.close();

pred.close();

socket.close();

sb.append(read);

tv.setText(sb);

}

  Thank you for your help

 I have added the permission <uses-permission
android:name="android.permission.INTERNET"></uses-permission>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to