마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

클래스에서 작동하는 함수들을 다른클래스에서 작동하게 불러오고 싶을때

0 추천

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);

 }

위주소의 소스에서 이부분에서 현재위치를 받아서 문자를 보내주는 코드를 실행해주고 싶은데 어떻게 해야할가요....

 

지미니v (1,080 포인트) 님이 2014년 6월 11일 질문

1개의 답변

0 추천
메소드 내용의 구성은 작성자님께서 하셔야 할것 같구..

private -> public 로 바꾸시면 될꺼 같은데요?
익명사용자 님이 2014년 6월 11일 답변
...