android.hardware.SensorManager#unregisterListener ( )源码实例Demo

下面列出了android.hardware.SensorManager#unregisterListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gsn   文件: AndroidLightWrapper.java
@Override
public void runOnce() {
	mSensorManager = (SensorManager) StaticData.globalContext.getSystemService(Context.SENSOR_SERVICE);
	mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
	updateWrapperInfo();
	try {
		if (dcDuration > 0){
			mSensorManager.registerListener(this, mSensor,SensorManager.SENSOR_DELAY_NORMAL); 
			Thread.sleep(dcDuration*1000);
			mSensorManager.unregisterListener(this);
		}
	}
	catch (InterruptedException e) {
		Log.e(e.getMessage(), e.toString());
	}
}
 
源代码2 项目: gsn   文件: AndroidGyroscopeWrapper.java
@Override
public void runOnce() {
	mSensorManager = (SensorManager) StaticData.globalContext.getSystemService(Context.SENSOR_SERVICE);
	mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
	updateWrapperInfo();
	try {
		if (dcDuration > 0){
			mSensorManager.registerListener(this, mSensor,60000); //around 16Hz 
			Thread.sleep(dcDuration*1000);
			mSensorManager.unregisterListener(this);
		}
	}
	catch (InterruptedException e) {
		Log.e(e.getMessage(), e.toString());
	}
}
 
源代码3 项目: Pedometer   文件: SensorListener.java
private void reRegisterSensor() {
    if (BuildConfig.DEBUG) Logger.log("re-register sensor listener");
    SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
    try {
        sm.unregisterListener(this);
    } catch (Exception e) {
        if (BuildConfig.DEBUG) Logger.log(e);
        e.printStackTrace();
    }

    if (BuildConfig.DEBUG) {
        Logger.log("step sensors: " + sm.getSensorList(Sensor.TYPE_STEP_COUNTER).size());
        if (sm.getSensorList(Sensor.TYPE_STEP_COUNTER).size() < 1) return; // emulator
        Logger.log("default: " + sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER).getName());
    }

    // enable batching with delay of max 5 min
    sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
            SensorManager.SENSOR_DELAY_NORMAL, (int) (5 * MICROSECONDS_IN_ONE_MINUTE));
}
 
源代码4 项目: BackPackTrackII   文件: StepCounterService.java
@Override
public void onDestroy() {
    Log.w(TAG, "Unregistering step counter listener");
    SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sm.unregisterListener(mStepCounterListener);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.edit().remove(SettingsFragment.PREF_LAST_STEP_COUNT).apply();

    super.onDestroy();
}
 
源代码5 项目: PermissionAgent   文件: SensorsTester.java
@Override
public boolean test() throws Throwable {
    SensorManager sensorManager = (SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
    try {
        Sensor heartRateSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
        sensorManager.registerListener(SENSOR_EVENT_LISTENER, heartRateSensor, 3);
        sensorManager.unregisterListener(SENSOR_EVENT_LISTENER, heartRateSensor);
    } catch (Throwable e) {
        PackageManager packageManager = mContext.getPackageManager();
        return !packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HEART_RATE);
    }
    return true;
}
 
源代码6 项目: PermissionAgent   文件: SensorsTester.java
@Override
public boolean test() throws Throwable {
    SensorManager sensorManager = (SensorManager)mContext.getSystemService(Context.SENSOR_SERVICE);
    try {
        Sensor heartRateSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
        sensorManager.registerListener(SENSOR_EVENT_LISTENER, heartRateSensor, 3);
        sensorManager.unregisterListener(SENSOR_EVENT_LISTENER, heartRateSensor);
    } catch (Throwable e) {
        PackageManager packageManager = mContext.getPackageManager();
        return !packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_HEART_RATE);
    }
    return true;
}
 
源代码7 项目: pandora   文件: SensorDetector.java
public void unRegister() {
    try {
        SensorManager manager = (SensorManager) Utils.getContext().getSystemService(Context.SENSOR_SERVICE);
        Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        manager.unregisterListener(this, sensor);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
源代码8 项目: weex   文件: AmbientLightManager.java
void stop() {
  if (lightSensor != null) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    sensorManager.unregisterListener(this);
    cameraManager = null;
    lightSensor = null;
  }
}
 
源代码9 项目: Study_Android_Demo   文件: AmbientLightManager.java
void stop() {
  if (lightSensor != null) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    sensorManager.unregisterListener(this);
    cameraManager = null;
    lightSensor = null;
  }
}
 
protected void unregisterSensor(Context context){
    if (!mRegistered) return;

    SensorManager mSensorManager = (SensorManager) context
            .getSystemService(Context.SENSOR_SERVICE);
    mSensorManager.unregisterListener(this);

    mRegistered = false;
}
 
源代码11 项目: BackPackTrackII   文件: PressureService.java
@Override
public void onDestroy() {
    Log.i(TAG, "Unregistering pressure listener");
    SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sm.unregisterListener(pressureListener);

    super.onDestroy();
}
 
源代码12 项目: android-motion-detector   文件: SensorsActivity.java
/**
 * {@inheritDoc}
 */
@Override
public void onStart() {
    super.onStart();

    try {
        sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

        sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER);
        if (sensors.size() > 0) sensorGrav = sensors.get(0);

        sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
        if (sensors.size() > 0) sensorMag = sensors.get(0);

        sensorMgr.registerListener(this, sensorGrav, SensorManager.SENSOR_DELAY_NORMAL);
        sensorMgr.registerListener(this, sensorMag, SensorManager.SENSOR_DELAY_NORMAL);
    } catch (Exception ex1) {
        try {
            if (sensorMgr != null) {
                sensorMgr.unregisterListener(this, sensorGrav);
                sensorMgr.unregisterListener(this, sensorMag);
                sensorMgr = null;
            }
        } catch (Exception ex2) {
            ex2.printStackTrace();
        }
    }
}
 
源代码13 项目: BookyMcBookface   文件: ReaderActivity.java
private void unlistenLight() {
    try {
        if (lightSensorListener != null) {
            SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            sensorManager.unregisterListener(lightSensorListener);
            lightSensorListener = null;
        }
    }  catch (Throwable t) {
        Log.e(TAG, t.getMessage(), t);
    }
}
 
源代码14 项目: StepSensor   文件: SensorStepService.java
/**
 * Allows to unregister to the {@link android.hardware.Sensor#TYPE_STEP_COUNTER} for counting step
 * thanks to the hardware chip.
 * Must calls {@link com.orangegangsters.github.lib.SensorStepServiceManager#isStepCounterFeatureAvailable(android.content.pm.PackageManager)} before to
 * know if the feature is available.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public void unregisterSensorStep() {
    if (mContext != null) {
        Log.d(TAG, "Unregister sensor listener");
        SensorManager sm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
        sm.unregisterListener(this);
        stopForeground(true);
    }
}
 
源代码15 项目: moVirt   文件: AmbientLightManager.java
public void stop() {
    if (lightSensor != null) {
        SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        sensorManager.unregisterListener(this);
        cameraManager = null;
        lightSensor = null;
    }
}
 
void stop() {
  if (lightSensor != null) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    sensorManager.unregisterListener(this);
    cameraManager = null;
    lightSensor = null;
  }
}
 
源代码17 项目: zxingfragmentlib   文件: AmbientLightManager.java
public void stop() {
  if (lightSensor != null) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    sensorManager.unregisterListener(this);
    cameraManager = null;
    lightSensor = null;
  }
}
 
源代码18 项目: Telegram-FOSS   文件: VoIPBaseService.java
@Override
public void onDestroy() {
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STOPPING ===============");
	}
	stopForeground(true);
	stopRinging();
	NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
	SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
	Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
	if (proximity != null) {
		sm.unregisterListener(this);
	}
	if (proximityWakelock != null && proximityWakelock.isHeld()) {
		proximityWakelock.release();
	}
	unregisterReceiver(receiver);
	if(timeoutRunnable!=null){
		AndroidUtilities.cancelRunOnUIThread(timeoutRunnable);
		timeoutRunnable=null;
	}
	super.onDestroy();
	sharedInstance = null;
	AndroidUtilities.runOnUIThread(new Runnable(){
		@Override
		public void run(){
			NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didEndCall);
		}
	});
	if (tgVoip != null) {
		updateTrafficStats();
		StatsController.getInstance(currentAccount).incrementTotalCallsTime(getStatsNetworkType(), (int) (getCallDuration() / 1000) % 5);
		onTgVoipPreStop();
		onTgVoipStop(tgVoip.stop());
		prevTrafficStats = null;
		callStartTime = 0;
		tgVoip = null;
	}
	cpuWakelock.release();
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if(!USE_CONNECTION_SERVICE){
		if(isBtHeadsetConnected && !playingSound){
			am.stopBluetoothSco();
			am.setBluetoothScoOn(false);
			am.setSpeakerphoneOn(false);
		}
		try{
			am.setMode(AudioManager.MODE_NORMAL);
		}catch(SecurityException x){
			if(BuildVars.LOGS_ENABLED){
				FileLog.e("Error setting audio more to normal", x);
			}
		}
		am.abandonAudioFocus(this);
	}
	am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));
	if (haveAudioFocus)
		am.abandonAudioFocus(this);

	if (!playingSound)
		soundPool.release();

	if(USE_CONNECTION_SERVICE){
		if(!didDeleteConnectionServiceContact)
			ContactsController.getInstance(currentAccount).deleteConnectionServiceContact();
		if(systemCallConnection!=null && !playingSound){
			systemCallConnection.destroy();
		}
	}

	ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
	VoIPHelper.lastCallTime=System.currentTimeMillis();
}
 
源代码19 项目: tinybus   文件: ShakeEventWire.java
@Override
protected void onStop() {
	SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
	sensorManager.unregisterListener(this);
	queue.clear();
}
 
源代码20 项目: 30-android-libraries-in-30-days   文件: Engine.java
private void unregisterSelfAsSensorListener(final SensorManager pSensorManager, final int pType) {
	final Sensor sensor = pSensorManager.getSensorList(pType).get(0);
	pSensorManager.unregisterListener(this, sensor);
}