0

I am working on an Android (kotlin) app which logs phonecall information (phone number, date and time). It works with incoming calls, but I fail to do it with outgoing.

I have tried a lot of solutions, but none of them seem to work.

This is the most recommended one:

override fun onReceive(context: Context?, intent: Intent?) {
    if(intent?.action.equals(Intent.ACTION_NEW_OUTGOING_CALL))
    {
        //Outgoing call
        String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    }
}

intent.action should be android.intent.action.ACTION_NEW_OUTGOING_CALL when there is an outgoing call made, but when I debug the app, the debugger shows that the action is android.intent.action.PHONE_STATE

Is there a way to fix this or some workaround?

tehcpu
  • 934
  • 1
  • 11
  • 23
ilinq
  • 25
  • 6

1 Answers1

0

Just try android.intent.action.NEW_OUTGOING_CALL action instead.

if (intent?.action == "android.intent.action.NEW_OUTGOING_CALL") {
    // ..
}
tehcpu
  • 934
  • 1
  • 11
  • 23