android detect is gyroscope available -
how can detect whether android device has gyroscope? i'm using following method detect whether gyroscope available. if gyroscope not available, use accelerometer.
sensormanager mgr = (sensormanager) getsystemservice(sensor_service); list<sensor> sensors = mgr.getsensorlist(sensor.type_all); (sensor sensor : sensors) { log.i("sensors",sensor.getname()); if(sensor.getname().contains("gyroscope")){ try{ msensormanager.registerlistener(this, msensormanager.getdefaultsensor(sensor.type_rotation_vector), sensormanager.sensor_delay_fastest); return; }catch(exception e){ } } } msensormanager.registerlistener(this, msensormanager.getdefaultsensor(sensor.type_accelerometer), sensormanager.sensor_delay_fastest);
however of app users complaint can't use gyroscope. there problem code?
you can use package manager's system features check if device has gyroscope in it:
packagemanager packagemanager = getpackagemanager(); boolean gyroexists = packagemanager.hassystemfeature(packagemanager.feature_sensor_gyroscope);
your current code may not work on devices sensor name not guaranteed contain gyroscope
in it.
Comments
Post a Comment