Search code examples
androidphone-call

making a list of outgoing calls one by one automatically


i want to make calls to list of phone numbers(4/5 numbers) from my phone;i made on call, after ending that call then only it has to call next number (which is automatically). what my thought is:

   for(int i=0;i<aray.lenght;i++)
   {
   callIntent=new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:"+num)); 
     startActivity(callintent);
  }

we know defaultly only two outgoing calls will go. i want to restrict one outgoing call has to go. and after talking/ ending ; next number will call, this process will continue until list of numbers over.here we also have to check the status of an outgoing call, ringing,offhookk and idle;how come we know or placed only single call by using three states. try to help.


Solution

  • try like this.. let nums be the list of numbers..

     public class CallsActivity extends Activity {
    
      final Context context = this;
         public String num;
         String LOG_TAG = "EMERGENCY CALL";
    
         public String[] pnum={"9666848344","9603939029","7404230210","9030109791"};
         ArrayList<String> b= new ArrayList<String>(Arrays.asList(pnum));
      public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         num=b.get(0);
        call(num);
        // add PhoneStateListener
        PhoneCallListener phoneListener = new PhoneCallListener();
        TelephonyManager telephonyManager = (TelephonyManager) this
            .getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener,
            PhoneStateListener.LISTEN_CALL_STATE);
    
    
    
      }
       void  call(String num1)
          {
            Intent callIntent=new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:"+num1));
            startActivity(callIntent);
            int indx=b.indexOf(num1);
    
            //Log.i(LOG_TAG, "indx"+indx);
             if (indx!=b.size())
                {
                    num=b.get(indx+1);
                }  
    
          }
    
      private class PhoneCallListener extends PhoneStateListener {
    
        private boolean isPhoneCalling = false;
    
    
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
    
          if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
          }
    
          if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(LOG_TAG, "OFFHOOK");
    
            isPhoneCalling = true;
          }
    
          if (TelephonyManager.CALL_STATE_IDLE == state) {
            // run when class initial and phone call ended, need detect flag
            // from CALL_STATE_OFFHOOK
            Log.i(LOG_TAG, "IDLE");
    
            if (isPhoneCalling) {
    
              Log.i(LOG_TAG, "CALL...");
    
          // restart app
          Intent i = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(
                  getBaseContext().getPackageName());
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //            startActivity(i);
             call(num);
              isPhoneCalling = false;
            }
    
          }
        }
      }
    
    }