0
我發送地理位置作爲短信到一些預定義的號碼,但下面的代碼不工作任何人都可以請telll我在下面的代碼中是錯誤的,如果我添加代碼只跟蹤位置它GIVS我的位置發送GSM位置AS短信給一些號碼android
// 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);
}
我已經設置了權限沒有在manifest.xml設置權限 – niknik123 2013-03-05 12:07:28