android - 自动生成一一拨出电话列表

标签 android phone-call

我想从我的手机调用电话号码列表(4/5 号码);我调用电话,结束该通话后只需调用下一个号码(自动)。我的想法是:

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

我们知道默认情况下只会调用两个电话。我想限制一个必须打出的电话。以及在谈话/结束之后;下一个号码会调用,这个过程会一直持续到号码列表结束。这里我们还必须检查去电调用的状态,振铃,摘机和空闲;为什么我们通过使用三个状态来知道或只调用了一个电话。尝试提供帮助。

最佳答案

尝试这样.. 让 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;
        }

      }
    }
  }

}

关于android - 自动生成一一拨出电话列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766002/

相关文章:

android - 存储我们数据的云数据库是否可用?

ViewGroup.resetResolvedTextDirection 中的 Android StackOverflowError

android - PhongGap Android Phone Call Activity 中

android - 如何使android textview自动链接其值作为电话号码

css - 单击链接或超链接图像时激活电话 - 给链接或图像 ID 时不起作用?

android - 如何在 xml 布局中添加两个 ScrollView ,使每个 ScrollView 占据布局高度的一半?

android - 如何在 ARCore 中检测眼睛的 Vetcor3 点或区域类型

android - 如何从通话记录中选择联系人?

java - 如何隐藏弹出 Activity 的标题栏

android - 在通话中显示信息