Hello.I try upload location with service and broadcast receiver...but no 
work....i have make for battery level and work....manifest is ok....this is 
my code.....


      private void buttonGetLocationClick() {
        getCurrentLocation(); // gets the current location and update 
mobileLocation variable
        
        if (mobileLocation != null) {
            locManager.removeUpdates(locListener); // This needs to stop 
getting the location data and save the battery power.
            
             londitude = "Londitude: " + mobileLocation.getLongitude();
             latitude = "Latitude: " + mobileLocation.getLatitude();
             altitiude = "Altitiude: " + mobileLocation.getAltitude();
            String accuracy = "Accuracy: " + mobileLocation.getAccuracy();
            String time = "Time: " + mobileLocation.getTime();

            editTextShowLocation.setText(londitude + "\n" + latitude + "\n"
                    + altitiude + "\n" + accuracy + "\n" + time);
            
            Intent intent = new Intent(this, MyBroadcastReceiver.class);
            intent.putExtra("lat",latitude);
            intent.putExtra("lon",londitude);
            
            
        } else {
            editTextShowLocation.setText("Sorry, location is not 
determined");
        }
    }

    public class MyBroadcastReceiver extends BroadcastReceiver { 
    
    @Override
      
      public void onReceive(Context context, Intent intent) {
        
        String latitude=intent.getStringExtra("lat");
        String londitude=intent.getStringExtra("lon");
        
        String strUrlup="http://www.xxxxx.net/location.php";;
        
        Intent service = new Intent(context, UploadService.class);
        
        service.putExtra("url", strUrlup );   
        service.putExtra("lats","30");
        service.putExtra("lons",londitude);
        
        context.startService(service);
        
        
    }

        

    } 

      public class UploadService extends IntentService {

      public UploadService() {
        super("UploadService");
      }

      // Will be called asynchronously be Android
      @Override
      protected void onHandleIntent(Intent intent) {
        
        String urlup = intent.getStringExtra("url");
        
        String lat1 = intent.getStringExtra("lats");
        String lon1 = intent.getStringExtra("lons"); 
        
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(urlup);
        try {
          List<NameValuePair> nameValuePairs = new 
ArrayList<NameValuePair>(2);
          nameValuePairs.add(new BasicNameValuePair("lat","30"));
          nameValuePairs.add(new BasicNameValuePair("lon",lon1));
          
          post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     
          HttpResponse response = client.execute(post);
          BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
          String line = "";
          while ((line = rd.readLine()) != null) {
            System.out.println(line);
          }

        } catch (IOException e) {
          e.printStackTrace();
        }
                
          }
          // Sucessful finished
}

    

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to