2013-02-11 76 views
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); 
} 

回答

0

也许你

+0

我已经设置了权限没有在manifest.xml设置权限 – niknik123 2013-03-05 12:07:28