getSystemServices is undefined when called in a Fragment?

前端 未结 7 1719
醉酒成梦
醉酒成梦 2020-12-08 18:59

I want TextViews to display the sensors readings in a Fragment. When trying to initialize the SensorManager the getSystemService

相关标签:
7条回答
  • 2020-12-08 19:24

    You can also get the context from the LayoutInflater.

    SensorManager sm = (SensorManager) getLayoutInflater().getContext().getSystemService(Context.SENSOR_SERVICE);
    
    0 讨论(0)
提交回复
热议问题