아래의 코드를 작성후 AVD에서 실행해보았습니다.

그리고 콘솔창을 통해

 

geo nmea $GPRMC,081836,A,3741.65,S,14507.36,E,000.0,360.0,155998,011.3,E*62

 

를 주었을때  LocationListener 는 반응하여 위치가 나왔으나

NMEA 데이터 onNmeaReceived는 전혀 받아들여지는게 없네요.

 

addNmeaListener 등록에는 성공했다는 리턴값이 들어오는데.. 정작 onNmeaReceived는 작동을 안하네요;;

 

옵티머스빅, 및 실제 몇개의 기기에서는 이상없이 동작했습니다..

 

혹시 onNmeaReceived는 실제기기에서만 동작하는건가요? AVD에서

NMEA 가상 데이터를 사용하여 옙을 만드는 방법은 없는건지 궁금합니다.

 

아 AVD 버전 2.2 , 2.3.3에서 테스트해보았습니다.

----------------------------------------------------------------------------------------------

 

package test.gps;

import android.app.Activity;
import android.content.Context;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

public class TstGPSActivity extends Activity {
    private LocationListener locListenD;
    public EditText etLatitude;
    public EditText etLongitude; 
    public EditText etAccuracy;
    public EditText etSpeed;
    public EditText etAltitude;
    public EditText etBearing;
    public EditText etSatellites;
    public EditText etNmea0183;

    private class MyNmeaListener implements GpsStatus.NmeaListener {
     
     public void onNmeaReceived(long timestamp, String nmea) {
      
      Log.w("SSS","~~~~~~~~~~~~~~~~~~~~");
      Editable e = etNmea0183.getText();
      int len = e.length();
      if(len > 5000) {
       e.delete(0, 2500);
      }
      
      e.append(nmea);
      
      len = e.length();
      etNmea0183.setSelection(len-1, len-1);
      
      if(nmea.startsWith("$GPGGA")) {
        String tokens[] = nmea.split(",");
        etSatellites.setText(tokens[7]);
      }
     }
    };
   
   
    private class MyLocationListener implements LocationListener {
     public void onLocationChanged(Location location) {
      etLatitude.setText(Double.toString(location.getLatitude()));
      etLongitude.setText(Double.toString(location.getLongitude()));
         etAccuracy.setText(Float.toString(location.getAccuracy()));
         etSpeed.setText(Float.toString(location.getSpeed()));
         etAltitude.setText(Double.toString(location.getAltitude()));
         etBearing.setText(Float.toString(location.getBearing()));
     }
     
     public void onProviderDisabled(String provider) {
      Toast.makeText(TstGPSActivity.this, provider + " Disabled", Toast.LENGTH_SHORT).show();
     }
     
     public void onProviderEnabled(String provider) {
      Toast.makeText(TstGPSActivity.this, provider + " Enabled", Toast.LENGTH_SHORT).show();
     }
     
     public void onStatusChanged(String provider, int status, Bundle extras) {
      switch(status) {
      case GpsStatus.GPS_EVENT_STARTED:
       Toast.makeText(TstGPSActivity.this, "GPS_EVENT_STARTED", Toast.LENGTH_SHORT).show();
       break;
       
      case GpsStatus.GPS_EVENT_STOPPED:
       Toast.makeText(TstGPSActivity.this, "GPS_EVENT_STOPPED", Toast.LENGTH_SHORT).show();
       break;
       
      case GpsStatus.GPS_EVENT_FIRST_FIX:
       Toast.makeText(TstGPSActivity.this, "GPS_EVENT_FIRST_FIX", Toast.LENGTH_SHORT).show();
       break;
       
      case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
       Toast.makeText(TstGPSActivity.this, "GPS_EVENT_SATELLITE_STATUS", Toast.LENGTH_SHORT).show();
       break;
      }
     }
    };
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
     //Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        //startActivity(gpsOptionsIntent);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        etLatitude = (EditText)findViewById(R.id.etLatitude);
        etLongitude = (EditText)findViewById(R.id.etLongitude);
        etAccuracy = (EditText)findViewById(R.id.etAccuracy);
        etSpeed = (EditText)findViewById(R.id.etSpeed);
        etAltitude = (EditText)findViewById(R.id.etAltitude);
        etBearing = (EditText)findViewById(R.id.etBearing);
        etSatellites = (EditText)findViewById(R.id.etSatellites);
        etNmea0183 = (EditText)findViewById(R.id.etNmea0183);

        LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
         etLatitude.setText("DISABLED GPS");
         etLongitude.setText("DISABLED GPS");
        } else {
         Location ll = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
         if(ll != null) {
       etLatitude.setText(Double.toString(ll.getLatitude()));
       etLongitude.setText(Double.toString(ll.getLongitude()));
         }
          
         MyNmeaListener nmeaListen = new MyNmeaListener();
         if(!lm.addNmeaListener(nmeaListen)){
          Log.w("Msg","add 실패");
         }else{
          Log.w("Msg","add 성공.!!!!");
         }
        
         locListenD = new MyLocationListener();
         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 0.5f, locListenD);
        }
    }
}

 

---------------------------------------------------------------------------------------------------------------