2013-07-16 2 views
1

코드 및 정보를 찾기 위해 실제로 노력했지만 사실이 코드는이 사이트의 다른 질문과 답변을 기반으로합니다. 그럼에도 불구하고, 내가 뭘 잘못하고 있는지 모르겠다. 이 코드는 백그라운드 서비스에 있습니다. 이 코드로 수행하려고 시도하는 작업은 기본적으로 gpsTimeValue주기에 GPS 기반 위치가 포함 된 SMS를 보내는 것입니다. Thread.sleep (시간)은 시간을 측정하는 정확한 방법은 아니지만 중요하지는 않습니다.단일 SMS를 통해 장치 GPS 위치 전송

if (locateMode) 
// start location manager 
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

// entering locate mode 
while (locateMode) { 
    handler.post(new DisplayToast("Entering locate mode")); 

    // check value of sleep time 
    gpsTimeValue = Integer.parseInt(pref.getString("gps_time_value", getString(R.string.gpsTimeDefault))) * 6000; 

    // update notification 
    msg = "Starting GPS cycle with " + gpsTimeValue; 
    handler.post(new DisplayToast(msg)); 
    notificationBuilder.setContentText(msg); 
    notificationManager.notify(notificationId, 
    notificationBuilder.build()); 

    // send location sms 
    sendLocationSMS(pref.getString("send_to_number", ""),locationManager); 

    // sleep 
    try { 
     Thread.sleep(gpsTimeValue); 
    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } 

    // check location mode 
    if (pref.getString("locate_mode", "OFF").equalsIgnoreCase("OFF")) { 
     locateMode = false; 
     handler.post(new DisplayToast("Exiting locate mode")); 
    } 
} 

그리고 이것은 sendLocationSMS의 코드입니다.

private void sendLocationSMS(final String sendToNumber, 
          LocationManager locationManager) { 

    handler.post(new DisplayToast("Seting up SMS to number: "+ sendToNumber)); 

    LocationListener locationListener = new LocationListener() { 

     public void onLocationChanged(Location location) { 
      // Called when a new location is found by the listener 
      String loc = location.toString(); 
      String message = "Location" + loc; 

      handler.post(new DisplayToast(message)); 

      if (!sendToNumber.isEmpty()) { 
       SmsManager smsManager = SmsManager.getDefault(); 
       smsManager.sendTextMessage(
             sendToNumber, null,message,null, null); 
      } 
     } 

     @Override 
     public void onProviderDisabled(String provider) {} 

     @Override 
     public void onProviderEnabled(String provider) {} 

     @Override 
     public void onStatusChanged(String provider, int status,Bundle extras) {} 
    }; 
    //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
                0,0, locationListener); 
      locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, locationListener, null); 

} 

그래서, 모든 토스트 (나는 handler.post 건배 (newDisplay (메시지))) onLocationChange 내부의 코드를 제외하고 보여됩니다 : I 명시 적으로 GPS 기반 위치를 원한다. 나는 전화로 어떻게 든 위치가 어떻게 든 활성화되는 것을 본다. (나는 청취자 설정 때문에 생각한다.) 그러나 아무런 메시지도 보내지 않고 어떤 위치도 만들어 내지 않는다. 나는 requestLocationUpdates와 requestSingleUpdate를 시도했다. 그 중에서도

, 나는 다음과 같이 매니페스트에이 코드와 관련된 권한이 :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.SEND_SMS"/> 

내 응용 프로그램에서 모든 코드의 모든 다른 부분이 제외 매력처럼 작동합니다. 그것은 내 견과를 몰고있어, 나는 그것을 해결하는 방법을 모른다. 제발, 어떤 충고도 환영받을 것입니다. 감사. 이것은 당신이) (메시지

locationText = location.getLatitude() + ","+ location.getLongitude를 통해 위치 정보를 얻을 수 있도록해야한다

답변

0

;

smsManager.sendTextMessage (phoneNo, null, locationText, null, null);

관련 문제