这曾经像
sSensorManager = (SensorManager)this.getSystemService(SENSOR_SERVICE);
在一项活动中,现在是片段我正在制作如下
sSensorManager = (SensorManager)rootView.getContext().getSystemService(SENSOR_SERVICE);
然后我在SENSOR_SERVICE下方获得红线,如下所示
SENSOR_SERVICE cannot be resolved to a variable
答案 0 :(得分:5)
在Fragment
sSensorManager = (SensorManager)getActivity().getSystemService(getActivity().SENSOR_SERVICE);
答案 1 :(得分:0)
无论您身在何处,都可以像static Constant
sSensorManager = (SensorManager)rootView.getContext().getSystemService(Context.SENSOR_SERVICE);