Android SensorManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SensorManager class.

This code example shows how to use the following methods:unregisterListener
		 
	} 
	 
	public void stop() 
	{ 
		this.sensorManager.unregisterListener(this);
	} 
	 
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub 
		 
	} 
 
	public void onSensorChanged(SensorEvent event) {
		// We want to know what temp this is. 
		float temp = event.values[0];
		mAppView.loadUrl("javascript:gotTemp(" + temp + ")");
	} 
 
} 
10
CodeRank
This code example shows how to use the following methods:unregisterListener
		 
	} 
	 
	public void stop() 
	{ 
		this.sensorManager.unregisterListener(this);
	} 
	 
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub 
		 
	} 
 
 
	public void onSensorChanged(SensorEvent event) {
		// We only care about the orientation as far as it refers to Magnetic North 
		float heading = event.values[0];
		mAppView.loadUrl("javascript:gotBearing(" + heading + ")");
	} 
} 
10
CodeRank
This code example shows how to use the following methods:unregisterListener
	} 
	 
	public void stop() 
	{ 
		if(started)
			sensorManager.unregisterListener(this);
	} 
	 
	 
 
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub 
		 
	} 
 
	public void onSensorChanged(SensorEvent event) {		
		if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
			return; 
		long curTime = System.currentTimeMillis();
		if (lastUpdate == -1 || (curTime - lastUpdate) > mTime) {		
10
CodeRank
This code example shows how to use the following methods:getDefaultSensor, registerListener
		assertTrue(shadow.hasListener(listener));
	} 
	 
	private SensorEventListener registerListener() {
		SensorEventListener listener = new TestSensorEventListener();
		Sensor sensor = sensorManager.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER);
		sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
		 
		return listener;
	} 
	 
	@Test 
	public void shouldReturnHasNoListenerAfterUnregisterListener() { 
		SensorEventListener listener = registerListener();
		sensorManager.unregisterListener(listener, sensorManager.getDefaultSensor(SensorManager.SENSOR_ACCELEROMETER));
		 
		assertFalse(shadow.hasListener(listener));
	} 
	 
	@Test 
8
CodeRank
This code example shows how to use the following methods:getDefaultSensor, registerListener
                    *SensorManager.GRAVITY_EARTH;
    this.gap=gap;
    this.cb=cb;
     
    mgr=(SensorManager)ctxt.getSystemService(Context.SENSOR_SERVICE);
    mgr.registerListener(listener,
                          mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                          SensorManager.SENSOR_DELAY_UI);
  } 
   
  public void close() { 
    mgr.unregisterListener(listener);
  } 
   
  private void isShaking() { 
    long now=SystemClock.uptimeMillis();
     
    if (lastShakeTimestamp==0) {
      lastShakeTimestamp=now;
       
8
CodeRank
This code example shows how to use the following methods:getDefaultSensor, registerListener
This code example shows how to use the following methods:getDefaultSensor
This code example shows how to use the following methods:getDefaultSensor, registerListener, unregisterListener
This code example shows how to use the following methods:getDefaultSensor, registerListener, unregisterListener
7
CodeRank
This code example shows how to use the following methods:getDefaultSensor
 
	public Cocos2dxAccelerometer(final Context pContext) {
		this.mContext = pContext;
 
		this.mSensorManager = (SensorManager) this.mContext.getSystemService(Context.SENSOR_SERVICE);
		this.mAccelerometer = this.mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 
		final Display display = ((WindowManager) this.mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		this.mNaturalOrientation = display.getOrientation();
	} 
 
	// =========================================================== 
	// Getter & Setter 
	// =========================================================== 
 
	public void enable() { 
		this.mSensorManager.registerListener(this, this.mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
	} 
 
        public void setInterval(float interval) {
8
CodeRank

Related Android SensorManager Questions & Answers:

Other Android SensorManager Examples

12:	public class MainActivity extends Activity {
13:	
14:	  private static SensorManager sensorService;
15:	  private MyCompassView compassView;
16:	  private Sensor sensor;
-
23:	    setContentView(compassView);
24:	
25:	    sensorService = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
26:	    sensor = sensorService.getDefaultSensor(Sensor.TYPE_ORIENTATION);
27:	    if (sensor != null) {

Read More

See Code Examples for Android SensorManager Methods: