0

i have an application making a call for specific phone number, if the number not response the application make an action, my question is: how can i know if the there is a response or not ?!

here is my code:

PhoneCallListener phoneListener = new PhoneCallListener();      
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);



    Button emr = (Button) findViewById (R.id.emergButton);
    emr.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Model m = new Model () ;
            num=m.getAdminPhone();
            String Numb = "tel:"+num;
              Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse(Numb));
                startActivity(callIntent);

            if () // here i want to making a check...
            {answer = true;}



        }
    });
Egor
  • 39,695
  • 10
  • 113
  • 130

2 Answers2

0

This answer should help.

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

private PhoneStateListener mPhoneListener = new PhoneStateListener() {

     public void onCallStateChanged(int state, String incomingNumber) {
        try {
            if (state == TelephonyManager.CALL_STATE_OFFHOOK){
                // Call wasn't answered
            }
        } catch (RemoteException e) {}
     } 
};
Community
  • 1
  • 1
Cameron
  • 84
  • 1
  • 11
0

There seems to be no way to get a result from the dialer. This topic might help you to realize that. So, using @Cameron approach seems better.

Isn't it funny to fill an answer to make another answer accepted ? ;)

Snicolas
  • 37,840
  • 15
  • 114
  • 173