如何使用应用程序获取 android 手机(例如加速度计、陀螺仪、GPS、摄像头馈送)的传感器读数?
How do I get sensor readings of an android mobile (eg. accelerometer, gyroscope, GPS, Camera feed) using app?
我想制作一个应用程序来获取 android phone 的所有读数,例如加速度计、gps、陀螺仪、摄像头等。记录所有这些数据并将其发送到云到服务器使用。
我是初学者 android 开发人员,想基本了解如何从移动设备中可用的所有传感器获取读数 phone。
所以这里有一些参考,供大家理解。基本上,当您谈论 Sensors
时,就像您所说的 Accelerometer
和 Gyroscope
一样。
这就是你如何控制 Sensors
Sensor accelerometer;
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
} else {
Toast.makeText(this, "No sensor available", Toast.LENGTH_SHORT).show();
}
同样,您可以处理设备中所有可用的传感器。
Make sure you check whether the sensor is available in device.
现在当我们谈论 Camera
和 GPS
他们不是 Sensors
他们是 Hardware
所以你需要硬件许可才能控制Camera
like
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
要了解有关 Camera
的更多信息,请参阅此 link
类似,GPS
是获取用户位置我建议你阅读整个Location
文档here
希望这对您有所帮助...
我想制作一个应用程序来获取 android phone 的所有读数,例如加速度计、gps、陀螺仪、摄像头等。记录所有这些数据并将其发送到云到服务器使用。
我是初学者 android 开发人员,想基本了解如何从移动设备中可用的所有传感器获取读数 phone。
所以这里有一些参考,供大家理解。基本上,当您谈论 Sensors
时,就像您所说的 Accelerometer
和 Gyroscope
一样。
这就是你如何控制 Sensors
Sensor accelerometer;
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
} else {
Toast.makeText(this, "No sensor available", Toast.LENGTH_SHORT).show();
}
同样,您可以处理设备中所有可用的传感器。
Make sure you check whether the sensor is available in device.
现在当我们谈论 Camera
和 GPS
他们不是 Sensors
他们是 Hardware
所以你需要硬件许可才能控制Camera
like
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
要了解有关 Camera
的更多信息,请参阅此 link
类似,GPS
是获取用户位置我建议你阅读整个Location
文档here
希望这对您有所帮助...