Execute a dart function in background while receiving a call
Here MyPhoneReceiver.java is not needed...
change MyBroadcastReceiver code to this...
package com.ashbu.flutterappbackground;import android.app.Service;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.telephony.PhoneStateListener;import android.widget.Toast;import android.telephony.TelephonyManager;public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { TelephonyManager telephony = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE); telephony.listen(new PhoneStateListener(){ @Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); System.out.println("incomingNumber : "+incomingNumber); Toast.makeText(context, "TeleDuce Customer "+ incomingNumber, Toast.LENGTH_LONG).show(); } },PhoneStateListener.LISTEN_CALL_STATE); }}
The main thing is to give phonecall access from mobile to the app...(in permission settings)