1

I want to get the incoming caller's phone number in my flutter app. I'm trying the solution in this answer, but it doesn't work.

I have no knowledge about it at all and have not been able to find a resource with all the stages. What am I doing wrong?

The full code: https://github.com/gulsenkeskin/phone_call_demo

Gülsen Keskin
  • 657
  • 7
  • 23

2 Answers2

2

I solved the problem. If anyone needs it, he can look at this link

Gülsen Keskin
  • 657
  • 7
  • 23
-1

You can't do this in Flutter. To receive incoming call you should go for native, in the number String you will receive the incoming caller's number.

package com.anand.example;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;


public class CallReceiver extends BroadcastReceiver {
  
    String number = "";
  
    @Override
    public void onReceive(Context context, Intent intent) {

        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        if (number != null) {
            if (number != null) {
                if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                    System.out.println(number);
                    // call attended

                } else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                    // call ended
                    System.out.println(number);
                } else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                    System.out.println(number);
                    // incoming call

                }
            }
        }


    }


}
Anand
  • 4,355
  • 2
  • 35
  • 45