public class Lo extends Activity implements LocationListener{
private LocationManager locManager;
Geocoder geoCoder;
private Location myLocation = null;
double latPoint = 0;
double lngPoint = 0;
SQLiteDatabase sqldb;
DBHelper db;
String b;
ImageButton gpsButton,sendButton;
String i,j,k;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lo);
db = new DBHelper(getApplicationContext());
// TODO Auto-generated method stub
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// LocationListener의 핸들을 얻음
// GPS로 부터 위치정보 받음
// locManagser.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,
// 5, this);
// 네트워크로 위치정보를 받음
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
1000, 5, this);
// 주소를 확인함
geoCoder = new Geocoder(this, Locale.KOREAN);
gpsButton = (ImageButton)findViewById(R.id.gpsButton);
sendButton = (ImageButton)findViewById(R.id.sendButton);
gpsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GetLocations();
}
});
}
public void GetSns(){
// TODO Auto-generated method stub
sqldb = db.getWritableDatabase();
Cursor cursor = sqldb.rawQuery("SELECT * FROM CallDB;",null);
while(cursor.moveToNext()){
b = cursor.getString(0);
}
String a="sms:ok";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("0"+b, null, "위도:"+k+"경도:"+j+"주소:"+i, null, null);
Toast.makeText(getApplicationContext(),a , Toast.LENGTH_SHORT).show();
cursor.close();
sqldb.close();
}
public void GetLocations() {
StringBuffer juso = new StringBuffer();
if (myLocation != null) {
latPoint = myLocation.getLatitude();
lngPoint = myLocation.getLongitude();
try {
// 위도,경도를 이용하여 현재 위치의 주소를 가져온다.
List<Address> addresses;
addresses = geoCoder.getFromLocation(latPoint, lngPoint, 1);
for (Address addr : addresses) {
int index = addr.getMaxAddressLineIndex();
for (int i = 0; i <= index; i++) {
juso.append(addr.getAddressLine(i));
juso.append(" ");
}
juso.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
k = String.valueOf(latPoint);
j = String.valueOf(lngPoint);
i = String.valueOf(juso);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
GetSns();
}
public void onLocationChanged(Location location) {
Log.d("location", "location changed");
myLocation = location;
GetLocations();
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
public void onStatusChanged(String s, int i, Bundle bundle) {
}
}
--------------------------현재위치를 받아와서 문자로 보내주는 코드입니다.----------------------------
http://blog.naver.com/wlalsqqq/220026729443
// 연결 실패했을때 이코드가 있습니다 윗 주소에
private void connectionFailed() {
setState(STATE_LISTEN);
}
위주소의 소스에서 이부분에서 현재위치를 받아서 문자를 보내주는 코드를 실행해주고 싶은데 어떻게 해야할가요....