2012-03-19 133 views
2

我想拨打电话号码列表(4/5号码)从我的手机;我打了电话,在结束该通话后,只有它必须拨打下一个号码(这是自动)。我的想法是:自动拨打一个电话列表

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

我们知道默认情况下只有两个去电会去。我想限制一个去电。并在谈话/结束后;下一个号码将会呼叫,这个过程将继续,直到数字清单结束。我们还必须检查呼出,振铃,摘机和闲置状态;我们如何通过使用三种状态知道或放置单一呼叫。尝试帮助。

回答

2

尝试这样的.. 让NUMS是数字列表..

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; 
     } 

     } 
    } 
    } 

}