My source code is:
import android.content.Context;
import android.hardware.SensorManager;
public class ShakeEvent implements SensorEventListener {
private static SensorManager sensorManager;
...
...
public static boolean isSupported (){
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
I receive error message that getSystemService function is undefined.
I tried to write this row also in such way:
sensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
But then I receive error message that getContext() function is undefined for ShakeEvent object.
How should I write it? Thanks.
Your class doesn’t seem to reference any
Contextobject.getSystemService()is aContextmethod, so you need a reference to context object (like anActivity) when creating theSensorEventListener. Then you’ll be able to callcontext.getSystemService().