제가 GPS 위성수가 필요해서 찾다 보니까..
http://www.androidpub.com/100151
Called when the provider status changes. This method is called when a provider is unable to fetch a location or if the provider has recently become available after a period of unavailability.
| provider | the name of the location provider associated with this update. |
|---|---|
| status | OUT_OF_SERVICE if the provider is out of service, and this is not expected to change in the near future; TEMPORARILY_UNAVAILABLE if the provider is temporarily unavailable but is expected to be available shortly; and AVAILABLE if the provider is currently available. |
| extras | an optional Bundle which will contain provider specific status variables.
A number of common key/value pairs for the extras Bundle are listed below. Providers that use any of the keys on this list must provide the corresponding value as described below.
|
A number of common key/value pairs for the extras Bundle are listed below. Providers that use any of the keys on this list must provide the corresponding value as described below.
메니페스트에서 userpermission 을 하나 주어야 하는데
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
이걸 선안하시면 되고
소스는 아래에
package name 은 알아서 만들어 보시면 될 것 같네요.
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
public class GpsTestApp extends Activity implements LocationListener {
/** Called when the activity is first created. */
private final String GPS_TAG = "Gps tag";
public final static long INTERVAl_TIME = 500;
public final static float INTERVAl_DIS = 0f;
private GpsStatus mGpsStatus;
private LocationManager locManager;
private Iterable<GpsSatellite> itGpsStatellites;
// gpsstatuslistener
private final GpsStatus.Listener gpsStatusListener = new GpsStatus.Listener(){
public void onGpsStatusChanged (int event ) {
switch(event){
case GpsStatus.GPS_EVENT_STARTED:
Log.e(GPS_TAG,String.valueOf(event)+"---GPS_EVENT_STARTED");
break;
case GpsStatus.GPS_EVENT_STOPPED:
Log.e(GPS_TAG,String.valueOf(event)+"---GPS_EVENT_STOPPED");
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
Log.e(GPS_TAG,String.valueOf(event)+"---GPS_EVENT_FIRST_FIX");
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
mGpsStatus = locManager.getGpsStatus(null);
itGpsStatellites = mGpsStatus.getSatellites();
Iterator<GpsSatellite> it = itGpsStatellites.iterator();
int iPos = 0;
while(it.hasNext()){
GpsSatellite gpsS = (GpsSatellite)it.next();
// gpsInfo.iID[iPos] = gpsS.getPrn();
// gpsInfo.iAzimuth[iPos] = (int)gpsS.getAzimuth();
// gpsInfo.iElevation[iPos] =(int)gpsS.getElevation();
// gpsInfo.iSN[iPos] = (int)gpsS.getSnr();
iPos++;
}
// gpsInfo.iStateNum = iPos;
// mGpsHandler.setGpsInfo(gpsInfo);
Log.e(GPS_TAG,String.valueOf(event)+"---GPS_EVENT_SATELLITE_STATUS");
break;
default:
break;
}
}
};
private final GpsStatus.NmeaListener gpsStatusNmeaListener = new GpsStatus.NmeaListener(){
public void onNmeaReceived(long timestamp, String nmea) {
// TODO Auto-generated method stub
Log.e(GPS_TAG,nmea);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, INTERVAl_TIME, INTERVAl_DIS, this);
locManager.addGpsStatusListener(gpsStatusListener);
locManager.addNmeaListener(gpsStatusNmeaListener);
}
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
감사합니다. 덕분에 힌트를 얻었네요.
NMEA 프로토콜을 직접 받아 $GPGGA 쪽을 파싱해서 처리했습니다 ^^
$GPGGA 8번째가 위성수입니다.
GpsStatus.NmeaListener m_nmea_listener = new GpsStatus.NmeaListener(){
public void onNmeaReceived(long timestamp, String nmea) {
// TODO Auto-generated method stub
// $GPGGA,054208.000,3725.973,N,12709.561,E,1,05,1.90,141.50,M,160.50,M,,*58
// Log.d(LOG_TAG,nmea);
String str_temp[] = nmea.split(",");
if(str_temp[0].equals("$GPGGA")) {
Log.d(LOG_TAG,str_temp[7]); // 수신된 위성수를 로그에 출력
}
};



