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 retrieve the system service you want.