This is the code i am using for detecting incoming calls and i am toasting the incoming number at the same time, i want to launch my application automatically so please help me do this.Thanks in advance. I have referred to the solution of this question before also and in that the questioner was not able to detect incoming calls and the answer showed how to detect the incoming calls but i have already done that as shown in the code above and now i want code to launch my application automatically whenever the phone rings but i could not find solution to this there.
public class CallHelper extends Activity {
String incomingNo;
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// called when someone is ringing to this phone
incomingNo = incomingNumber;
Toast.makeText(ctx,
"Incoming no: "+incomingNo,
Toast.LENGTH_SHORT).show();
break;
}
}
}
public class OutgoingReceiver extends BroadcastReceiver {
public OutgoingReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(ctx,
"Outgoing: "+number,
Toast.LENGTH_LONG).show();
}
}
private Context ctx;
private TelephonyManager tm;
private CallStateListener callStateListener;
private OutgoingReceiver outgoingReceiver;
public CallHelper(Context ctx) {
this.ctx = ctx;
callStateListener = new CallStateListener();
outgoingReceiver = new OutgoingReceiver();
}
public String returnData(){
String incoming = incomingNo;
start();
callStateListener = new CallStateListener();
Log.i("check","this is return data returning :"+incoming);
return incoming;
}
public void start() {
tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);
}
public void stop() {
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
ctx.unregisterReceiver(outgoingReceiver);
}
}