ilinq
ilinq

Reputation: 25

Android intent action wrong when making an outgoing call

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?

Upvotes: 0

Views: 282

Answers (1)

tehcpu
tehcpu

Reputation: 966

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

if (intent?.action == "android.intent.action.NEW_OUTGOING_CALL") {
    // ..
}

Upvotes: -1

Related Questions