以下のコードは電話の場所を教えてくれますが、メッセージは送信されません。
ロケーションマネージャーの減速の前にSMSコードを与えると、メッセージまたは試行の前に送信されます。
try{
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
String message;
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
String loc=location.toString();
// Toast.makeText(getApplicationContext(), loc,Toast.LENGTH_LONG).show();
String phoneNumber="5556";
message="this is amog and it is my current location "+loc;
sendSMS(phoneNumber, message);
Toast.makeText(getApplicationContext(), message,Toast.LENGTH_LONG).show();
sendSMS(phoneNumber, message);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}catch(Exception e){
Toast.makeText(getApplicationContext(), e.getMessage(),Toast.LENGTH_LONG).show();
}