2

Any one help to display the NMEA sentence like $GPRMC ..... I am using the below code:

public class SampleNMEA extends Activity implements LocationListener, GpsStatus.Listener,GpsStatus.NmeaListener{

    LocationManager lm;
    TextView output;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        output = (TextView)findViewById(R.id.out);
        lm = (LocationManager) getSystemService(LOCATION_SERVICE);

        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
        final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);


        output.append("\nBelow Data is about the your location:");

        output.append("\n\n\nLatit:"+location.getLatitude());
        output.append("\n\nLongitude:"+location.getLongitude());
        output.append("\n\nTime: "+location.getTime());


    }
    public void onLocationChanged(Location location) 
    {
        output.append("\n\n\nLatitude:"+location.getLatitude());
        output.append("\n\nLongitude:"+location.getLongitude());
        output.append("\n\nTime: "+location.getTime());
    }

    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String arg0, int arg1, Bundle arg2) 
    {
         lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
        final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        output.append("\n\n\nLatitude:"+location.getLatitude());
        output.append("\n\nLongitude:"+location.getLongitude());
        output.append("\n\nTime: "+location.getTime());


}

    public void onGpsStatusChanged(int event) 
    {

    }
    public void onNmeaReceived(long timestamp, String nmea) 
    {
        output.append("NMEA Sentence: "+nmea);

    }

    }

Any one help I added permissions in manifest.xml

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
Puja Surya
  • 1,155
  • 4
  • 20
  • 47
Jagan
  • 128
  • 2
  • 4
  • 10
  • Hey Jagan, Are you solved your problem? I want to do the same operation but I am not able to do that. I want to get currently used satellite info as well as latitude and longitude from using NMEAListener. So can you please do me a favor, can you please share your code so that I can found my mistake and I can get more idea from that. Thanks in advance. – anddev Apr 09 '12 at 08:06

6 Answers6

5

Change your provider to GPS_PROVIDER.

You can get the nmea sentence by Gps provider.

Change this line

     **lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);**

to

     **lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000,10,this);**

Now check in onNmeaReceived() method.

Adel Khayata
  • 2,717
  • 10
  • 28
  • 46
4

Just add a NmeaListener

  public class SampleNMEA extends Activity implements LocationListener, GpsStatus.Listener,GpsStatus.NmeaListener{
LocationManager lm;
TextView output;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    output = (TextView)findViewById(R.id.out);
    lm = (LocationManager) getSystemService(LOCATION_SERVICE);

    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
    final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);


    output.append("\nBelow Data is about the your location:");

    output.append("\n\n\nLatit:"+location.getLatitude());
    output.append("\n\nLongitude:"+location.getLongitude());
    output.append("\n\nTime: "+location.getTime());
   //add listener here
    lm.AddNmeaListener(this);





}
1

I have Samsung Galaxy Spica and yes, it doesn't work. However, I've installed 'ultra gps logger' (link) and NMEA data is correctly read. Perhaps author of this tool used different solution for reading NMEA which means that is possible.

zarius
  • 11
  • 1
0

If fakeGps is in list of installed apps, be sure to delete it and restart device in order to start receiving Nmea info. You can install free Nmea Info monitor from play market to test Nmea receiver on your device.

AlexInspired
  • 91
  • 2
  • 12
0

Are you calling addNmeaListener(GpsStatus.NmeaListener) to set that class as a listener? If not, you should!

To do so, call it like lm.addNmeaListener(this);.

Good luck & Regards

mdelolmo
  • 6,417
  • 3
  • 40
  • 58
  • I tried this also but its not responding properly.. simply the application saying "force Close" what i need to change for this any permission required in manifest file. – Jagan Jan 18 '11 at 08:02
  • 1
    You need to add permission android.permission.ACCESS_FINE_LOCATION to your Activity. But besides "Force Close", the log entry should provide more info. – mdelolmo Jan 18 '11 at 08:07
0

The conclusion being reached in this discussion here, is that NMEA doesn't work on some phones (the onNmeaReceived event never fires). ...but would love to be corrected on this.

Harry Wood
  • 2,220
  • 2
  • 24
  • 46