本文整理了Java中android.hardware.SensorManager.requestTriggerSensor()
方法的一些代码示例,展示了SensorManager.requestTriggerSensor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SensorManager.requestTriggerSensor()
方法的具体详情如下:
包路径:android.hardware.SensorManager
类名称:SensorManager
方法名:requestTriggerSensor
暂无
代码示例来源:origin: guardianproject/haven
public BumpMonitor(Context context) {
context.bindService(new Intent(context,
MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);
sensorMgr = (SensorManager) context.getSystemService(AppCompatActivity.SENSOR_SERVICE);
bumpSensor = sensorMgr.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
if (bumpSensor == null) {
Log.i("BumpMonitor", "Warning: no significant motion sensor");
} else {
boolean registered = sensorMgr.requestTriggerSensor(sensorListener, bumpSensor);
Log.i("BumpMonitor", "Significant motion sensor registered: "+registered);
}
}
代码示例来源:origin: guardianproject/haven
@Override
public void onTrigger(TriggerEvent event) {
Log.i("BumpMonitor", "Sensor triggered");
//value[0] = 1.0 when the sensor triggers. 1.0 is the only allowed value.
long curTime = System.currentTimeMillis();
// only allow one update every 100ms.
if (event.sensor.getType() == Sensor.TYPE_SIGNIFICANT_MOTION) {
if ((curTime - lastUpdate) > CHECK_INTERVAL) {
lastUpdate = curTime;
/*
* Send Alert
*/
Message message = new Message();
message.what = EventTrigger.BUMP;
try {
if (serviceMessenger != null) {
serviceMessenger.send(message);
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//re-register the listener (it finishes after each event)
boolean registered = sensorMgr.requestTriggerSensor(sensorListener, bumpSensor);
Log.i("BumpMonitor", "Significant motion sensor re-registered: "+registered);
}
};
代码示例来源:origin: qiubiteme/android_api_demos
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
protected void onResume() {
super.onResume();
if (mSigMotion != null && mSensorManager.requestTriggerSensor(mListener, mSigMotion))
mTextView.append(getString(R.string.sig_motion_enabled) + "\n");
}
代码示例来源:origin: THEONE10211024/ApiDemos
@Override
protected void onResume() {
super.onResume();
if (mSigMotion != null && mSensorManager.requestTriggerSensor(mListener, mSigMotion))
mTextView.append(getString(R.string.sig_motion_enabled) + "\n");
}
代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void listing16_6() {
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
// Listing 16-6: Registering a Trigger Event Listener
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
sensorManager.requestTriggerSensor(triggerEventListener, sensor);
}
代码示例来源:origin: lkorth/screen-notifications
private void registerPickupListener() {
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor pickupSensor = sensorManager.getDefaultSensor(25);
if (pickupSensor != null) {
sensorManager.requestTriggerSensor(new TriggerEventListener() {
@Override
public void onTrigger(TriggerEvent triggerEvent) {
new ScreenController(NotificationListener.this, false).handlePickup();
if (isWakeOnPickupEnabled()) {
registerPickupListener();
}
}
}, pickupSensor);
} else {
LoggerFactory.getLogger("NotificationListener").debug("No pickup listener available");
}
}
代码示例来源:origin: nvanbenschoten/RxSensor
@TargetApi(VERSION_CODES.JELLY_BEAN_MR2)
private static SensorManager mockSensorManager(final int events, final boolean result) {
SensorManager sensorManager = mock(SensorManager.class);
when(sensorManager.getDefaultSensor(GOOD_SENSOR)).thenReturn(mockSensor());
when(sensorManager.getDefaultSensor(BAD_SENSOR)).thenReturn(null);
final ArgumentCaptor<SensorEventListener> sensorArgument = ArgumentCaptor.forClass(SensorEventListener.class);
when(sensorManager.registerListener(sensorArgument.capture(), any(Sensor.class), anyInt(), any(Handler.class)))
.thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
for (int i = 0; i < events; i++) {
sensorArgument.getValue().onSensorChanged(mockSensorEvent());
}
return result;
}
});
final ArgumentCaptor<TriggerEventListener> triggerArgument = ArgumentCaptor.forClass(TriggerEventListener.class);
when(sensorManager.requestTriggerSensor(triggerArgument.capture(), any(Sensor.class)))
.thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
triggerArgument.getValue().onTrigger(mockTriggerEvent());
return result;
}
});
return sensorManager;
}
代码示例来源:origin: nvanbenschoten/RxSensor
boolean success = mSensorManager.requestTriggerSensor(listener, sensor);
if (!success) {
subscriber.onError(new SensorException(sensor));
内容来源于网络,如有侵权,请联系作者删除!