Problema con PhoneStateListener
Publicado por bjsr (1 intervención) el 12/08/2015 03:27:41
Hola a todos. Estoy desarrolando una aplicacion par grabar mis llamadas. Tengo dos clases que derivan de Broadcastreceiver que son las encargadas de detectar cuando se recibe y emite una llamada. Hasta aqui no hay problema ya que se crea un toast dependiendo del tipo de llamada y todo bien. Ambas clases llaman luego a una tercera que extiende de PhoneStateListener que es donde se graban las llamadas. El archivo de grabacion se guarda en el lugar respectivo y todo bien. El asunto es que para llamadas salientes funcion perfecto pero para llamdas entrantes al recibir la llamada la persona que me llama no me escucha, pareciera que se desactiva el microfono, aun cuando yo escucho a quien llama. En concreto el codigo del broadcastreceiver que llama al PhoneStateListener es el siguiente:
Phoneestado phoneListener = new Phoneestado(context);
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Log.d("PhoneStateReceiver::onReceive", "set PhoneStateListener");
El codigo de la clase que deriva de PhoneStateListener es el siguiente:
public class Phoneestado extends PhoneStateListener {
private boolean onCall = false;
MediaRecorder recorder = new MediaRecorder();
boolean recording=false;
int i=0;
String fname, inicio, total, total1, modo, interlocutor;
boolean recordStarted;
String phonenumber, horafin;
Date hora;
private static int fin, duracion;
private Context context;
public static String fina;
public static Date fecha3, fecha2;
private SQLiteDatabase baseDatos;
private static final String tablaLLA = "llamadas";
private static final String nombreBD = "agenda";
public Phoneestado(Context c) {
Log.i("CallRecorder", "PhoneListener constructor"); }
public void onCallStateChanged (int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.d("CallRecorder", "CALL_STATE_IDLE, stoping recording");
stopRecording();
final Calendar c = Calendar.getInstance();
fin = c.get(Calendar.MILLISECOND);
fina = String.valueOf(fin);
if (onCall == true) {
onCall = false;
}
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("CallRecorder", "CALL_STATE_RINGING");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("CallRecorder", "CALL_STATE_OFFHOOK starting recording");
startRecording();
break;
}
}
private void stopRecording() {
// TODO Auto-generated method stub
if(recording==true)
{
recorder.stop();
recorder.reset();
recorder.release();
recording=false;
}
}
private void startRecording() {
// TODO Auto-generated method stub
if(recording==false) {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
String file= Environment.getExternalStorageDirectory().toString();
File dir = new File("/sdcard/.Datos");
if(dir.mkdir()){
}
if (Outgoing.tipo1 == "Saliente"){
modo = "Saliente";
interlocutor=Outgoing.nombre;
}
if (Incoming.tipo1 == "Entrante"){
modo = "Entrante";
interlocutor=Incoming.nombre;
}
String filepath = dir + "/" + interlocutor + ".3gp";
recorder.setOutputFile(filepath);
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder.start();
recording=true;
}
}
}
No entiendo porque el error. Alguna ayuda sera apreciada. Saludos.
Phoneestado phoneListener = new Phoneestado(context);
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Log.d("PhoneStateReceiver::onReceive", "set PhoneStateListener");
El codigo de la clase que deriva de PhoneStateListener es el siguiente:
public class Phoneestado extends PhoneStateListener {
private boolean onCall = false;
MediaRecorder recorder = new MediaRecorder();
boolean recording=false;
int i=0;
String fname, inicio, total, total1, modo, interlocutor;
boolean recordStarted;
String phonenumber, horafin;
Date hora;
private static int fin, duracion;
private Context context;
public static String fina;
public static Date fecha3, fecha2;
private SQLiteDatabase baseDatos;
private static final String tablaLLA = "llamadas";
private static final String nombreBD = "agenda";
public Phoneestado(Context c) {
Log.i("CallRecorder", "PhoneListener constructor"); }
public void onCallStateChanged (int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.d("CallRecorder", "CALL_STATE_IDLE, stoping recording");
stopRecording();
final Calendar c = Calendar.getInstance();
fin = c.get(Calendar.MILLISECOND);
fina = String.valueOf(fin);
if (onCall == true) {
onCall = false;
}
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("CallRecorder", "CALL_STATE_RINGING");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("CallRecorder", "CALL_STATE_OFFHOOK starting recording");
startRecording();
break;
}
}
private void stopRecording() {
// TODO Auto-generated method stub
if(recording==true)
{
recorder.stop();
recorder.reset();
recorder.release();
recording=false;
}
}
private void startRecording() {
// TODO Auto-generated method stub
if(recording==false) {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
String file= Environment.getExternalStorageDirectory().toString();
File dir = new File("/sdcard/.Datos");
if(dir.mkdir()){
}
if (Outgoing.tipo1 == "Saliente"){
modo = "Saliente";
interlocutor=Outgoing.nombre;
}
if (Incoming.tipo1 == "Entrante"){
modo = "Entrante";
interlocutor=Incoming.nombre;
}
String filepath = dir + "/" + interlocutor + ".3gp";
recorder.setOutputFile(filepath);
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder.start();
recording=true;
}
}
}
No entiendo porque el error. Alguna ayuda sera apreciada. Saludos.
Valora esta pregunta


0