package com.samples.location.findbestproviders;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class FindBestProvidersActivity extends Activity {
	

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        
        final TextView text = (TextView)findViewById(R.id.text);
                       
        LocationManager manager = (LocationManager)getSystemService(
      				  Context.LOCATION_SERVICE);
      		
        text.append("List of Location providers\n");	
        List<String> providers = manager.getAllProviders();
      		for (int i = 0; i < providers.size(); i++) {
      			String provider = providers.get(i);
      			text.append("\nProvider: " + provider);
      			text.append("\nEnabled: " + 
      					manager.isProviderEnabled(provider) + "\n");
      	}                
      		
      	Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAltitudeRequired(true);
        criteria.setBearingRequired(true);
        criteria.setCostAllowed(true);
        criteria.setSpeedRequired(true);
        
        String bestProvider = manager.getBestProvider(criteria, true);
        text.append("\nBest provider: " + bestProvider);               
    }
}
