0

Here is My Manifest File :

<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name = "android.permission.READ_PHONE_STATE"/>

Here is my Java Code :

  switch (state){
            case TelephonyManager.CALL_STATE_RINGING:
                Toast.makeText(getApplicationContext(),"Ringing....",Toast.LENGTH_LONG).show();
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                Toast.makeText(getApplicationContext(),"onCall....",Toast.LENGTH_LONG).show();
                onCall= true;
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                if(onCall == true){
                    Toast.makeText(getApplicationContext(),"Restarting app",Toast.LENGTH_LONG).show();
                    //restarting application
                    Intent restart = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
                    restart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(restart);
                    onCall= false;
                }
                break;
            default:
                break;
        }

How to identify when someone picks our call and how to do it?

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
sivaram siva
  • 242
  • 2
  • 7

1 Answers1

0

You need to create Broadcast Receiver for detect call.

 public class PhoneStatReceiver extends BroadcastReceiver{
    @Override

    public void onReceive(Context context, Intent intent) {
        TelephonyManager tm =  (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);

        if(tm.getCallState()==TelephonyManager.CALL_STATE_OFFHOOK)
        {
            Toast.makeText(context,"Accepted",Toast.LENGTH_SHORT).show();
        }

    } }