本文介绍了通过仿真器设定温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模拟器上运行此code读取温度的变化,但它从来没有检测到温度变化 onSensorChanged()。我用这个命令通过远程登录工具来改变温度:

I run this code on the emulator to read temperature change, but it never detects the temperature change at onSensorChanged(). I use this command to change temperature through the telnet tool:

传感器设定温度1:2:3

sensor set temperature 1:2:3

我做了什么错?

public class SensorActivity extends Activity implements SensorEventListener {
  private SensorManager mSensorManager;
  private Sensor mysensor;

  @Override
  public final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mysensor = mSensorManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE);

  }
    public void printText(String text)
    {

        EditText et=(EditText)findViewById(R.id.editText1);
        et.setText(text);

    }
  @Override
  public final void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Do something here if sensor accuracy changes.
      String text=sensor.getName()+"accuracy = " + accuracy;
      printText(text);
  }

  @Override
  public final void onSensorChanged(SensorEvent event) {

    String text = "OnSensorChanged";
    printText(text);
  }

  @Override
  protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(this, mysensor, SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  protected void onPause() {
    super.onPause();
    mSensorManager.unregisterListener(this);
  }
}

感谢

推荐答案

当你创建的模拟器,你有没有给它的硬件?打开AVD,寻找硬件部分,单击新建,并增加温度支持。

When you created the emulator, did you give it the hardware?Open AVD, look for the Hardware section, click "New" and add "Temperature Support."

这篇关于通过仿真器设定温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:00