Reputation: 3574
I need detect the outgoing calls and send the number as text message to another number. Is there any way to detect outgoing calls. I have tried phonestatelistener but it doesn't work.
Upvotes: 3
Views: 3869
Reputation: 1055
If you mean detect the time of an outgoing call starts ringing on the other phone, then I can tell that there is NO way (sadly) to do that.
It's impossible to detect by regular non-system application - no Android API. I could not find a way, I was googling the solution within very long time.
Upvotes: 2
Reputation: 11948
please see following link to Detect Outgoing call:
Detecting incoming and outgoing phone calls on Android
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();
}
}
Register the broadcast receiver:
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);
Upvotes: 2
Reputation: 2628
Try this code
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
number = incomingNumber;
Thread_calls.run();
//Toast.makeText(ctx, "Incoming: " + incomingNumber,Toast.LENGTH_LONG).show();
break;
}
}
}
public class OutgoingReceiver extends BroadcastReceiver {
public OutgoingReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Thread_calls.run();
//Toast.makeText(ctx, "Outgoing: " + number, Toast.LENGTH_LONG).show();
}
}
Upvotes: 1
Reputation: 5077
I hope this will help you
Uri allCalls = Uri.parse("content://call_log/calls");
Cursor c = managedQuery(allCalls, null, null, null, null);
String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for number
String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration
int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going
and a tutorial for more information Link
Upvotes: 1