当State Call响铃时执行命令

时间:2014-01-29 11:48:29

标签: java android

我在Android中有一个小应用程序。

所以我有几个Button,每个按钮首先调用一个特定的中间数字。 在第一次通话后,我必须等待〜15秒,应用程序必须调用真正的号码。

例如,我点击一个名为“toto”的按钮,电话号码是001,所以应用程序首先打电话给中间号码,例如000,并且会有一个声音说他必须等待几个到达托托之前的几秒钟。

现在我有了这个:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

TelephonyManager telephoneM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        PhoneStateListener listner = new PhoneStateListener() {

            public void onCallStateChanged(int state, String incomingnumber) {
                String etat = "N/A";
                switch (state) {
                case TelephonyManager.CALL_STATE_IDLE:
                    etat = "pas de reponse";
                    Toast.makeText(MainActivity.this, "" + etat,
                            Toast.LENGTH_SHORT).show();
                    break;
                case TelephonyManager.CALL_STATE_RINGING:
                    etat = "sonne";
                    Toast.makeText(MainActivity.this, "" + etat,
                            Toast.LENGTH_SHORT).show();
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    etat = "en ligne";
                    Toast.makeText(MainActivity.this, "" + etat,
                            Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        };
telephoneM.listen(listner, PhoneStateListener.LISTEN_CALL_STATE);

Btoto = (Button) findViewById(R.id.num1);
Btoto.setOnClickListener(this);

public void onClick(View v) {

        switch (v.getId()) {
        case R.id.num1:
            Intent localIntent = new Intent("android.intent.action.CALL");
            localIntent.setData(Uri.parse("tel:0153204255")); // the intermediate number
            startActivity(localIntent);
//here I have to make a delay after the first ringing

// And here i have to make the real call to toto

            break;

有人可以给我一些建议吗?

谢谢

0 个答案:

没有答案