[英]Android proximity sensor when uncoverd
I work in project where i use proximity sensor my program should mute the phone when the proximity sensor is covered and restore it to normal when the sensor is uncovered. 我在使用接近传感器的项目中工作,当接近传感器被覆盖时,我的程序应使手机静音,并在发现传感器时将其恢复为正常。 i managed to code for when the sensor is covered but i don't know the value for far when the sensor is uncovered i need a code to unmute when the sensor is uncovered.
我设法对何时盖住传感器进行了编码,但是我不知道传感器被发现时的远距离值,我需要代码才能在传感器被发现时取消静音。
@Override
public void onSensorChanged(SensorEvent event) {
audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if(event.sensor.getType()==Sensor.TYPE_PROXIMITY){
if(event.values[0]<5){ audio.setRingerMode(AudioManager.RINGER_MODE_youwant);}else{ audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);}
}
}
Here is the code for mute/unmute 这是静音/取消静音的代码
AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
int current_volume =mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
//If you want to player is mute ,then set_volume variable is zero.Otherwise you may supply some value.
int set_volume=0;
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,set_volume, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.