本文整理汇总了Java中android.hardware.Sensor.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Sensor.getType方法的具体用法?Java Sensor.getType怎么用?Java Sensor.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.Sensor
的用法示例。
在下文中一共展示了Sensor.getType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.hardware.Sensor; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//assim como em LocationManager a gente pega um tipo de provider (GPS_PROVIDER)
//com sensores, não há APIs dedicadas para sensores, usamos o SensorManager
//os sensores são identificados por nomes (TYPE_LINEAR_ACCELERATION)
//existem sensores e tipos de sensores
//abaixo, estamos pedindo todos os sensores, de todos os tipos
List<Sensor> allSensors = new ArrayList<>(sensorManager.getSensorList(Sensor.TYPE_ALL));
List<Sensor> sensors = new ArrayList<>();
//removendo trigger sensors, que entregam apenas uma única leitura
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
for (Sensor s : allSensors) {
boolean triggerSensor = s.getType() == Sensor.TYPE_SIGNIFICANT_MOTION ||
s.getType() == Sensor.TYPE_STEP_COUNTER ||
s.getType() == Sensor.TYPE_STEP_DETECTOR;
if (!triggerSensor) {
sensors.add(s);
}
}
}
else {
sensors = allSensors;
}
adapter=new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensors);
setListAdapter(adapter);
}
示例2: onSensorChanged
import android.hardware.Sensor; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
Sensor mySensor = sensorEvent.sensor;
Log.i(TAG, "onSensorChanged");
if (mySensor.getType() == Sensor.TYPE_STEP_COUNTER) {
WritableMap map = Arguments.createMap();
long curTime = System.currentTimeMillis();
//i++;
if ((curTime - lastUpdate) > delay) {
final Object o = sensorEvent.values[0];
Log.i("History", "Data point:" + sensorEvent.values[0]);
map.putDouble("steps", sensorEvent.values[0]);
sendEvent(this.mReactContext, "StepSensorChangedEvent", map);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mReactContext.getApplicationContext(), "" + o, Toast.LENGTH_SHORT).show();
}
});
lastUpdate = curTime;
}
}
}
示例3: onSensorChanged
import android.hardware.Sensor; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent event) {
Sensor sensor = event.sensor;
synchronized (this) {
if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
calc_step(event);
}
}
}
示例4: isXYZ
import android.hardware.Sensor; //导入方法依赖的package包/类
private boolean isXYZ(Sensor s) {
switch (s.getType()) {
case Sensor.TYPE_ACCELEROMETER:
case Sensor.TYPE_GRAVITY:
case Sensor.TYPE_GYROSCOPE:
case Sensor.TYPE_LINEAR_ACCELERATION:
case Sensor.TYPE_MAGNETIC_FIELD:
case Sensor.TYPE_ROTATION_VECTOR:
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (s.getType() == Sensor.TYPE_GAME_ROTATION_VECTOR
|| s.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED
|| s.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
return true;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (s.getType() == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR) {
return true;
}
}
return false;
}
示例5: onAccuracyChanged
import android.hardware.Sensor; //导入方法依赖的package包/类
/**
* Used to handle change of accuracy from the sensors. We will only check pulse accuracy
* @param sensor
* @param i
*/
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
//set the accuracy of the pulse snsors
if (sensor.getType()==Sensor.TYPE_HEART_RATE)
{
accuracySensorPulse=i;
}
}
示例6: onSensorChanged
import android.hardware.Sensor; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
Sensor evtSensor = event.sensor;
if(evtSensor.getType()==Sensor.TYPE_ACCELEROMETER)
{
double x = event.values[0];
double y = event.values[1];
double maxValue = Math.sqrt(x*x+y*y);
double xDiv = x/maxValue;
double yDiv = y/maxValue;
// Calculates new falling angle
double angle = Math.atan(yDiv/xDiv) + (x < 0 ? Math.PI : 0);
float accY = accG*(float)Math.sin(angle);
float accX = -accG*(float)Math.cos(angle);
// Push new angle data to RS
if(scriptMain != null) {
scriptMain.set_accY((float) accY);
scriptMain.set_accX((float) accX);
}
}
}
示例7: onSensorChanged
import android.hardware.Sensor; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
Sensor mySensor = event.sensor;
float x = 0;
float y = 0;
float z = 0;
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
if ((Math.sqrt(x*x + y*y + z*z) < FREEFALL_THRESHOLD) && !firstTimeAlert){
if(am.isMicrophoneMute()){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE, 0);
}
else {
// Note that this must be the same instance of audioManager that mutes
// http://stackoverflow.com/questions/7908962/setstreammute-never-unmutes?rq=1
am.setStreamMute(AudioManager.STREAM_ALARM, false);
}
}
mediaPlayer.setLooping(true);
mediaPlayer.start();
firstTimeAlert = true;
mediaPlayerOncePlayed = true;
this.startService(mLocationSendServiceIntent);
}
}