हां, ऐसा कुछ है।
आप सेंसर ईवेंट प्राप्त करने के लिए SensorManager का उपयोग कर सकते हैं। उदाहरण के लिए, प्रकाश Sensor आप के लिए उपयोगी हो जाएगा:
private SensorManager sensorManager;
private Sensor lightSensor;
private float lightAmount;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
SensorEventListener listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
// returns the current light amount
lightAmount = event.data[0];
}
lightSensor.registerListener(listener);
}
लेकिन निश्चित रूप से वह अकेले सब काम नहीं कर सकते। स्क्रीन को चमकदार होने पर यह देखने के लिए अपने प्रकाश संवेदक को प्रोग्राम करें, यदि सही है कि का अर्थ है कि उपयोगकर्ता अब इसे नहीं देख रहा है। और आप एक्सेलेरोमीटर का उपयोग कर सकते हैं (जैसा कि आपने कहा था) आपकी मदद करने के लिए। मैं कुछ कोड मिल गया है और अनुकूलित यह, वर्ग कुछ इस तरह होना चाहिए:
public class AccelerometerDetector {
boolean isAvailable = false;
boolean isEnabled = false;
/**
* Constructor.
*
* @param enable : True to enable the accelerometer
* @throws UnsupportedOperationException
* - thrown if the Accelerometer is not available on the current device.
*/
public AccelerometerDetector(boolean enable)
throws UnsupportedOperationException
{
/* Check if the sensor is available */
for (String accelerometer : Sensors.getSupportedSensors())
if (accelerometer.equals(Sensors.SENSOR_ACCELEROMETER))
isAvailable = true;
if (!accelerometerAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
if (enable)
setEnableAccelerometer(true);
}
/**
* Set if the Accelerometer is enabled or not.
*
* @param enable
* @throws UnsupportedOperationException
*/
public void setEnableAccelerometer(boolean enable)
throws UnsupportedOperationException
{
if (!accelerometerAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
/* If should be enabled and isn't already */
if (enable && !this.isEnabled) {
Sensors.enableSensor(Sensors.SENSOR_ACCELEROMETER);
this.isEnabled = true;
} else /* If should be disabled and isn't already */
if (!enable && this.isEnabled) {
Sensors.disableSensor(Sensors.SENSOR_ACCELEROMETER);
this.isEnabled = false;
}
}
/**
* Read the values provided by the Accelerometer.
*
* @return Current Accelerometer-values.
* @throws UnsupportedOperationException
* if the Accelerometer is not available on this device.
* @throws IllegalStateException
* if the Accelerometer was disabled.
*/
public float[] readAccelerometer()
throws UnsupportedOperationException, IllegalStateException
{
if (!isAvailable)
throw new UnsupportedOperationException(
"Accelerometer is not available.");
if (!this.isEnabled)
throw new IllegalStateException(
"Accelerometer was disabled.");
/* Get number of sensor-values the sensor will return. Could be
* variable, depending of the amount of axis (1D, 2D or 3D
* accelerometer). */
int sensorValues = Sensors
.getNumSensorValues(Sensors.SENSOR_ACCELEROMETER);
float[] values = new float[sensorValues];
/* Make the OS fill the array we passed. */
Sensors.readSensor(Sensors.SENSOR_ACCELEROMETER, values);
return values;
}
}
इसके अलावा अपने Manifest.xml में इस सुविधा की घोषणा:
क्या आप "उपस्थिति सेंसर" कहा जाता है हो सकता है लाइट/निकटता सेंसर। लेकिन आप निकटता सेंसर का उपयोग नहीं कर सकते क्योंकि यह आमतौर पर केवल 5 सेमी रेंज है।
स्रोत
2012-12-19 15:45:48
आमतौर पर यदि मैं एक्स चाहता हूं तो मैं वाई की तलाश करूंगा: निष्क्रियता -> http://stackoverflow.com/questions/4208730/how-to-detect-user-inactivity-in-android संबंधित एक उत्तर भी है उपयोगकर्ता द्वारा गतिविधि। –
एसआईआईआई चेहरे की विशेषताओं के लिए समय-समय पर जांच करने के लिए सामने वाले कैमरे का उपयोग करता है। (दस्तावेज़ों में जानकारी है, जिसमें एक चेतावनी भी शामिल है कि यह इसे सक्षम करके बैटरी जीवन को कम कर देता है।) –
लेकिन @ केनहाइट, मुझे लगता है कि एक तरह का "चेहरा पहचान" सॉफ़्टवेयर (या चिपसेट) भी है। क्या आप जानते हैं कि इसका उपयोग करना संभव है? या आपके ऐप को अपना चेहरा पहचान करने की ज़रूरत है? मुझे पता है कि आईओएस के बारे में मूल कार्य है। –