SensorManager -----传感器管理类

本文介绍了Android中的SensorManager类,它是设备传感器的访问入口。通过Context.getSystemService(SENSOR_SERVICE)获取实例。主要内容包括如何管理传感器,如getSensorList、registerListener和unregisterListener等方法的使用。特别提醒,当活动暂停时务必关闭不需要的传感器,以避免快速消耗电池。官方提供了一个实现SensorEventListener接口并进行注册、注销监听器的示例。
摘要由CSDN通过智能技术生成

安卓官方给予的解释:

     1、 SensorMananger lets you access the device's sensorsGet an instance of this class by  calling  Context.getSystemService()   with the argument SENSOR_SERVICE.”

    你可以用 Context.getSystemService(SENSOR_SERVICE)得到SensorManager的对象 ,有了它你就可以管理传感器了,其中包含下面提到的方法

   getSensorList

   registerListener

   unregisterListener等。

  2、Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will notdisable sensors automatically when the screen turns off.

    就是说要记得在不用的时候关掉传感器,因为手机黑屏是不会自动关掉传感器的

 

官网上给予的例子:

 public class SensorActivity extends Activity implements SensorEventListener {
      
     private final SensorManager mSensorManager;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值