当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager.getDefaultSensor方法代码示例

本文整理汇总了Java中android.hardware.SensorManager.getDefaultSensor方法的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.getDefaultSensor方法的具体用法?Java SensorManager.getDefaultSensor怎么用?Java SensorManager.getDefaultSensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.SensorManager的用法示例。


在下文中一共展示了SensorManager.getDefaultSensor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * Starts listening for shakes on devices with appropriate hardware.
 *
 * @return true if the device supports shake detection.
 */
public boolean start(SensorManager sensorManager) {
    // Already started?
    if (accelerometer != null) {
        return true;
    }

    accelerometer = sensorManager.getDefaultSensor(
            Sensor.TYPE_ACCELEROMETER);

    // If this phone has an accelerometer, listen to it.
    if (accelerometer != null) {
        this.sensorManager = sensorManager;
        sensorManager.registerListener(this, accelerometer,
                SensorManager.SENSOR_DELAY_FASTEST);
    }
    return accelerometer != null;
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:23,代码来源:ShakeDetector.java

示例2: toggleWakeUpWithProximityFeature

import android.hardware.SensorManager; //导入方法依赖的package包/类
private static void toggleWakeUpWithProximityFeature(boolean enabled) {
    try {
        if (enabled) {
            mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
            mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
                    .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        } else {
            unregisterProxSensorListener();
            mProxSensor = null;
            mSensorManager = null;
            mWakeLock = null;
        }
        if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:19,代码来源:ModPower.java

示例3: onCreate

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    initFragment();
    //display the fragment home witout any value


    //init the sensors
    sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
    sensor_pulse=sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
    sensor_step=sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
    //register the sensors
    sensorManager.registerListener(this,sensor_step,SensorManager.SENSOR_DELAY_NORMAL);
    //activate a thread for the pulse sensors


        //process information: 30 sec
        //stop time= 30 min
        threadPulse=new SensorsThreadLifecircle(this,sensor_pulse,30000,1000*60*30);
        threadPulse.start();

    displayFragmentHome();

    // Register the local broadcast receiver. make the ling between the Service and the view
    IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND);
    MessageReceiver messageReceiver = new MessageReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, messageFilter);

}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:31,代码来源:HomeActivity.java

示例4: startShakeDetection

import android.hardware.SensorManager; //导入方法依赖的package包/类
private void startShakeDetection() {
    shakeDetectionActive = true;
    // ShakeDetector initialization
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    Sensor mAccelerometer = mSensorManager
            .getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetector();
    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);

    final boolean finalAdditionalShakeDelay = additionalShakeDelay;
    mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() {

        @Override
        public void onShake() {
            if (finalAdditionalShakeDelay) {
                if (System.currentTimeMillis() > now + 3000) {
                    handleShakeEvent();
                }
            } else {
                handleShakeEvent();
            }
        }
    });
}
 
开发者ID:jonathansautter,项目名称:AutoOff,代码行数:25,代码来源:NotificationService.java

示例5: start

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * Start listening for shakes.
 */
public void start(SensorManager manager) {
  Assertions.assertNotNull(manager);
  Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  if (accelerometer != null) {
    mSensorManager = manager;
    mLastTimestamp = -1;
    mCurrentIndex = 0;
    mMagnitudes = new double[MAX_SAMPLES];
    mTimestamps = new long[MAX_SAMPLES];

    mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
  }
}
 
开发者ID:coderminer,项目名称:GankIO_weex,代码行数:17,代码来源:ShakeDetector.java

示例6: onCreate

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar b = getActionBar();
    if (b!=null) b.hide();

    display = (TextView) findViewById(R.id.display);
    switchPhone = (Switch) findViewById(R.id.switchPhone);

    hellos = getResources().getStringArray(R.array.hello);
    byes = getResources().getStringArray(R.array.bye);
    convos = getResources().getStringArray(R.array.convo);

    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);


    findViewById(R.id.about_link).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent about = new Intent(MainActivity.this, AboutActivity.class);
            startActivity(about);
        }
    });


}
 
开发者ID:quaap,项目名称:PhoneFoneFun,代码行数:31,代码来源:MainActivity.java

示例7: onCreate

import android.hardware.SensorManager; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG,"onCreate()");
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:16,代码来源:AccelerometerSensorService.java

示例8: CompassTile

import android.hardware.SensorManager; //导入方法依赖的package包/类
public CompassTile(Object host, String key, XSharedPreferences prefs,
        QsTileEventDistributor eventDistributor) throws Throwable {
    super(host, key, prefs, eventDistributor);

    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
    mAccelerationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGeomagneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:10,代码来源:CompassTile.java

示例9: start

import android.hardware.SensorManager; //导入方法依赖的package包/类
public void start(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
    SharedPreferences sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(context);
    if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
        SensorManager sensorManager = (SensorManager) context
                .getSystemService(Context.SENSOR_SERVICE);
        lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        if (lightSensor != null) {
            sensorManager.registerListener(this, lightSensor,
                    SensorManager.SENSOR_DELAY_NORMAL);
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:15,代码来源:AmbientLightManager.java

示例10: isSupportStepCountSensor

import android.hardware.SensorManager; //导入方法依赖的package包/类
public static boolean isSupportStepCountSensor(Context context) {
    // 获取传感器管理器的实例
    SensorManager sensorManager = (SensorManager) context
            .getSystemService(Context.SENSOR_SERVICE);
    Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
    return countSensor != null || detectorSensor != null;
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:9,代码来源:HomeFragment.java

示例11: init

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * Function to init compass activity
 */
private void init() {
    countryName = (TextView) findViewById(R.id.textView11);
    if (MainActivity.locationInfo != null)
        countryName.setText(getResources().getConfiguration()
                .locale.getDisplayLanguage().equals("العربية")
                ? ConfigPreferences.getLocationConfig(this).name_english
                : ConfigPreferences.getLocationConfig(this).name);

    //init compass activity views
    Quibladegree = (TextView) findViewById(R.id.textView12);
    Quibladegree.setText(getString(R.string.qibla_direction) + " " + ConfigPreferences.getQuibla(this));
    indicator = (ImageView) findViewById(R.id.imageView2);
    compass = (RelativeLayout) findViewById(R.id.compassContainer);
    compassMapContainer = (RelativeLayout) findViewById(R.id.compassMapContainer);
    compassMain = (RelativeLayout) findViewById(R.id.compassMain);
    smallCircleLevel = (ImageView) findViewById(R.id.smallCircle);
    innerPosition = (RelativeLayout) findViewById(R.id.innerplace);
    pointerIndicatorInner = (ImageView) findViewById(R.id.poinerInner);
    redCircle = (ImageView) findViewById(R.id.red_circle);
    errorImage = (ImageView) findViewById(R.id.error);

    //init sensor services
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    compassLevel = (ImageView) findViewById(R.id.compassLevel);

    //animate compass pointer
    RotateAnimation ra = new RotateAnimation(currentDegree, MainActivity.quiblaDegree,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    ra.setDuration(400);
    ra.setFillAfter(true);
    indicator.startAnimation(ra);
    pointerIndicatorInner.startAnimation(ra);
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:39,代码来源:CompassActivity.java

示例12: Compass

import android.hardware.SensorManager; //导入方法依赖的package包/类
Compass(Context context) {
    mainActivity = (CompassActivity) context;
    mSensorManager = (SensorManager) mainActivity.getSystemService(Context.SENSOR_SERVICE);
    mLocationManager = (LocationManager) mainActivity.getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(mainActivity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(mainActivity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
    {
        warn("請檢查本應用程式是否授權使用『位置』及『儲存』", 0);
        mainActivity.finish();
        return;
    }
    mProvider = mLocationManager.getProvider(LocationManager.GPS_PROVIDER);
    if (mProvider == null) {
        warn("未支援 GPS", 0);
        mainActivity.finish();
        return;
    }
    minTime = (long) (SECONDS_TO_MILLISECONDS);
    minDistance = 0;

    gSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    oSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    rSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
    mProj = new Proj();
    cpdb = new CPDB(context);
    restore();
}
 
开发者ID:wade-fs,项目名称:Military-North-Compass,代码行数:29,代码来源:Compass.java

示例13: AccelerometerReader

import android.hardware.SensorManager; //导入方法依赖的package包/类
public AccelerometerReader(Context ctx) 
    throws UnsupportedOperationException { 
  SensorManager sensor_manager = (SensorManager) ctx.getSystemService(
      Context.SENSOR_SERVICE);
  Sensor accelerometer = sensor_manager.getDefaultSensor(
      Sensor.TYPE_ACCELEROMETER);
  sensor_manager.registerListener(listener_, accelerometer,
  		                            SensorManager.SENSOR_DELAY_FASTEST); 
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:10,代码来源:AccelerometerReader.java

示例14: onCreate

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    //setting up the broadcast

    am = (AudioManager)(getApplicationContext().getSystemService(Context.AUDIO_SERVICE));
    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.siren);
    mediaPlayer.setLooping(true);

    sensorManager = (SensorManager)getSystemService(getApplicationContext().SENSOR_SERVICE);
    sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    sensorManager.registerListener(this, sensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    mBroadcastReceiver = new SMSBroadcastReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(mBroadcastReceiver, filter);


    IntentFilter newFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mReceiver, newFilter);


    PowerManager manager =
            (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PhoneLocatorService.class.getName());

    // Create a notification area notification so the user
    // can get back to the PhoneLocator Service and Close It

    final Intent notificationIntent = new Intent(getApplicationContext(),
            NirbhayaActivity.class);
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    final Notification notification = new Notification.Builder(
            getApplicationContext())
            .setSmallIcon(R.drawable.ic_launcher)
            .setOngoing(true).setContentTitle("Nirbhaya")
            .setContentText("Click to Access Nirbhaya Service")
            .setContentIntent(pendingIntent).build();

    // Put this Service in a foreground state, so it won't
    // readily be killed by the system
    startForeground(NOTIFICATION_ID, notification);

    firstTimeAlert = false;
    mLocationSendServiceIntent = new Intent(NirbhayaActivity.getMainApp(), LocationSendService.class);
}
 
开发者ID:sommukhopadhyay,项目名称:nirbhaya,代码行数:51,代码来源:PhoneLocatorService.java

示例15: SensorEventUtil

import android.hardware.SensorManager; //导入方法依赖的package包/类
public SensorEventUtil(Activity activity) {
	mSensorManager = (SensorManager) activity.getSystemService(activity.SENSOR_SERVICE);
	mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);// TYPE_GRAVITY
	// 参数三,检测的精准度
	mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);// SENSOR_DELAY_GAME
}
 
开发者ID:FacePlusPlus,项目名称:MegviiFacepp-Android-SDK,代码行数:7,代码来源:SensorEventUtil.java


注:本文中的android.hardware.SensorManager.getDefaultSensor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。