/ / Hot zum Erfassen der Breiten- und Längenwerte, wenn ich eine bestimmte Wählscheibe auf dem Telefon wähle - Android

Heiß, um die Breiten- und Längenwerte zu sammeln, wenn ich ein bestimmtes auf meinem Telefonwählblock anwähle - android

public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

String phonenum = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
if (phonenum.equals("111")) {

locationmanager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationlistener);
Toast.makeText(context, "The Gps values are..." + lon, Toast.LENGTH_LONG).show();

}

}
}

private static LocationListener locationlistener = new LocationListener() {

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
}
};

Hallo, wenn ich auf meiner Wählscheibe 111 meine app wähleIst auf meinem Gerät vorinstalliert, sollte der Breiten- und der Logitude-Wert auf Toast eingestellt werden. Ich habe eine Beispiel-App ausprobiert, die eine Toast-Nachricht auf der Vorwahlnummer 111 anzeigt, wobei der Rundfunkempfänger verwendet wird und Logitude-Werte von dieser Funktion.

Antworten:

0 für die Antwort № 1
private Location getLastBestLocation() {
Location locationGPS = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Location locationNet = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

long GPSLocationTime = 0;
if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); }

long NetLocationTime = 0;

if (null != locationNet) {
NetLocationTime = locationNet.getTime();
}

if ( 0 < GPSLocationTime - NetLocationTime ) {
return locationGPS;
}
else {
return locationNet;
}}