I want to determine the direction of calls on my app. When I run the app on my real device, making a call of which is an outgoing, under the LogCat, the direction appears as Outgoing : (Dialed Number), of which is fine by me.
But when I get an incoming call, I still get this Outgoing : (Incoming Number)
What might be the reason for this? I tried to swap my code around and see what changes it might bring it, but still no luck.
Someone who might have experienced the same thing, or know where the problem is please.
There is my code:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state == null) {
// outgoing call
String number = intent.getStringExtra(intent.EXTRA_PHONE_NUMBER);
Log.i("TAG", "OUTGOING: " + phoneNumber);
//String direction = number;
}
else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
// incoming call
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.i("TAG", "INCOMING: " + phoneNumber);
String direction = number;
}
I tried to swap my code around where String number = intent.getStringExtra(intent.EXTRA_PHONE_NUMBER);
to String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); and after my else if statement change the
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);to
String number = intent.getStringExtra(intent.EXTRA_PHONE_NUMBER);` and see what changes it might bring it, but still no luck.
@Override public int onStartCommand(Intent intent, int flags, int startId) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state == null) {
// outgoing call
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.i("TAG", "OUTGOING: " + phoneNumber);
//String direction = number;
}
else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
// incoming call
String number = intent.getStringExtra(intent.EXTRA_PHONE_NUMBER);
Log.i("TAG", "INCOMING: " + phoneNumber);
String direction = number;
}