我发送Geo位置作为sms到一些预定义的号码,但以下代码无法正常工作任何人请告诉我wat下面的代码是错误的如果我添加代码只跟踪位置它给我的位置
// 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);
}
答案 0 :(得分:0)
也许你没有在Manifest.xml中设置权限