Monday, February 17, 2014

About phone RingMode problem


This is the level of your phone when muted, otherwise transferred back to the original ring pattern. But now becomes mute after not coming back, I do not know why.
 
package com.example.test;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;

public class MainActivity extends Activity {

private SensorManager sensorMgr = null;

private float x, y, z;
private int originalRingMode = -1;
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);

sensorMgr = (SensorManager) getSystemService (SENSOR_SERVICE);
Sensor sensor = sensorMgr.getDefaultSensor (Sensor.TYPE_ACCELEROMETER);
final AudioManager audiomanager = (AudioManager) getSystemService (Context.AUDIO_SERVICE);
originalRingMode = audiomanager.getRingerMode ();
SensorEventListener lsn = new SensorEventListener () {
public void onSensorChanged (SensorEvent e) {
x = e.values ​​[SensorManager.DATA_X];
y = e.values ​​[SensorManager.DATA_Y];
z = e.values ​​[SensorManager.DATA_Z];
setTitle ("x =" + x + "," + "y =" + (int) y + "," + "z =" + (int) z);

if ((int) z == 9 | | (int) z == 10)
/ / Here we can ignore, because the phone sometimes less, and so the z == 9 or 10
audiomanager.setRingerMode (AudioManager.RINGER_MODE_SILENT);
else
{
audiomanager.setRingerMode (originalRingMode);

}
}
public void onAccuracyChanged (Sensor s, int accuracy) {
}

};
/ / Register the listener, the third parameter is the detection accuracy
sensorMgr.registerListener (lsn, sensor,
SensorManager.SENSOR_DELAY_GAME);
}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}

}


<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nobody knows? These are the code, we help busy.
Reply:

Reply:
Dinga Dinga Dinga top

No comments:

Post a Comment