How is it possible that Google Fit app measures number of steps all the time without draining battery?

Thanks for asking this question! Battery is one of our top most concerns and we work hard to optimize Google Fit’s battery usage and provide a magical experience. Google Fit uses a mix of sensors(Accelerometer, Step counter, Significant Motion counter), Machine Learning and heuristics to get the data right. Our algorithm is pretty similar to … Read more

getSystemServices is undefined when called in a Fragment?

Just one more method call: sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); Why that one extra method call? the getSystemService() method that provides access to system services comes from Context. An Activity extends Context, a Fragment does not. Hence, you first need to get a reference to the Activity in which the Fragment is contained and then magically … Read more

How do I find out if the GPS of an Android device is enabled

Best way seems to be the following: final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { buildAlertMessageNoGps(); } private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(“Your GPS seems to be disabled, do you want to enable it?”) .setCancelable(false) .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { public void onClick(@SuppressWarnings(“unused”) final … Read more