0

位置情報を SMS として事前定義された番号に送信していますが、次のコードが機能しません。位置情報のみを追跡するコードを追加すると、下のコードが間違っていることを教えてください。

// Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) this
            .getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location
            // provider.
            Toast.makeText(getApplicationContext(), location.toString(), Toast.LENGTH_LONG).show();
            sendSMS(location);
        }

        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);
    Toast.makeText(getApplicationContext(),"end of pgm ", Toast.LENGTH_LONG).show();
}

static  void sendSMS(Location loc) {
    String phoneNumber = "8412866177";
    String location = loc.toString();
    Toast.makeText(null,location, Toast.LENGTH_LONG).show();
    // PendingIntent pi = PendingIntent.getActivity(this, 0, new
    // Intent(this, MainActivity.class), 0);
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, location, null, null);
}
4

1 に答える 1

0

Manifest.xml で権限を設定していない可能性があります

于 2013-02-11T09:49:04.793 に答える