Override Telephony Manager

Put your problem here if it does not fit any of the other categories.

Override Telephony Manager

Postby yoyoz » Sat Dec 05, 2009 7:37 pm

Hi,
i want to develop an addon for the telephony manager.
You click twice on the green button, and the speaker is automatically on.

I have made this source, but the original telephony manager override mine.
If you can help me or if you know an application like this.
I dont know how to override the telephony manager, and how activity can know if it should activate the speaker.


Thanks

My source is here if you want.
http://dl.free.fr/rm.pl?h=pdhGhpmX9&i=2 ... 6ekry77boL


First, my activity:
package fr.free.ynizon.callspeak;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.KeyEvent;

public class MainActivity extends Activity {
/** Called when the activity is first created. */

private boolean bSpeaker = false;
private boolean bSonnerie = false;
private Intent bindIntent;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ServiceCall mConnection = new ServiceCall();
bindIntent = new Intent(MainActivity.this, ServiceCall.class);
bindService(bindIntent, mConnection, Context.BIND_AUTO_CREATE);
startService(bindIntent);
unbindService(mConnection);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
switch (keyCode) {
case KeyEvent.KEYCODE_CALL:
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (bSpeaker){
bSpeaker = false;
}else{
bSpeaker = true;
}
audioManager.setSpeakerphoneOn(bSpeaker);
break;

case KeyEvent.KEYCODE_ENDCALL:
break;
}
return false;
}
}



Second my ServiceConnection:
package fr.free.ynizon.callspeak;

import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.AudioManager;
import android.os.Binder;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class ServiceCall extends Service implements ServiceConnection {
private ServiceCall serviceBinder;
private final IBinder binder = new MyBinder();

public boolean toto;

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
serviceBinder = ((ServiceCall.MyBinder)service).getService();
Log.i("ServiceCall", "Connexion du service");
}

@Override
public void onServiceDisconnected(ComponentName name) {
serviceBinder = null;
Log.i("ServiceCall", "Deconnexion du service");
}

@Override
public IBinder onBind(Intent intent) {
return binder;
}

@Override
public void onStart(Intent intent, int startId) {
String txtToast = "CallSpeak OK";//+startId;
Toast toast = Toast.makeText(getApplicationContext(), txtToast, Toast.LENGTH_SHORT);
toast.show();

// Mise en place du listener pour les appels
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
ListenerPhoneState listenerAppels = new ListenerPhoneState();
tManager.listen(listenerAppels, PhoneStateListener.LISTEN_CALL_STATE);
tManager.listen(listenerAppels, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);

/*
telephonyManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
PhoneStateListener.LISTEN_CALL_STATE |
PhoneStateListener.LISTEN_CELL_LOCATION |
PhoneStateListener.LISTEN_DATA_ACTIVITY |
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
PhoneStateListener.LISTEN_SERVICE_STATE |
PhoneStateListener.LISTEN_SIGNAL_STRENGTH);

telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
*/

}

public class MyBinder extends Binder {
ServiceCall getService() {
return ServiceCall.this;
}
}
}



Third:
public class ListenerPhoneState extends PhoneStateListener {
/** Called when the activity is first created. */

private boolean bSpeaker = false;
private boolean bSonnerie = false;

PhoneStateListener phoneStateListener = new PhoneStateListener() {
public void onCallForwardingIndicatorChanged(boolean cfi) {}
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE: {
//Rien
break;
}
case TelephonyManager.CALL_STATE_RINGING: {
// Sonnerie
bSonnerie = true;
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
// Raccrocher
bSpeaker = false;
bSonnerie = false;
break;
}
}
}
public void onCellLocationChanged(CellLocation location) {}
public void onDataActivity(int direction) {}
public void onDataConnectionStateChanged(int state) {
switch (state) {
case TelephonyManager.DATA_CONNECTED:
break;

case TelephonyManager.DATA_DISCONNECTED:
break;
}
}
public void onMessageWaitingIndicatorChanged(boolean mwi) {}
public void onServiceStateChanged(ServiceState serviceState) {}
public void onSignalStrengthChanged(int asu) {}
};

public boolean isBSpeaker() {
return bSpeaker;
}

public void setBSpeaker(boolean speaker) {
bSpeaker = speaker;
}

public boolean isBSonnerie() {
return bSonnerie;
}

public void setBSonnerie(boolean sonnerie) {
bSonnerie = sonnerie;
}

}
yoyoz
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Dec 05, 2009 7:27 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests