如何延迟拨出电话

时间:2016-06-15 07:02:54

标签: java android broadcastreceiver telephonymanager

是否可以选择延迟在Android中拨打电话?

一旦用户点击下面的呼叫按钮,就会调用方法。

public class DialBroadcastReceiver extends BroadcastReceiver {

   @Override
    public void onReceive(Context context, Intent intent) {

        Log.v("DileBroadCastReceiver","In onReceive()");

        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

            Log.v("DialBroadcast Receiver","Number is: "+number);
        }
    }
}

然后对手用户接听电话。

我需要的是当用户点击呼叫按钮时我应该延迟一两秒钟,是否有任何选择可以这样做。

我是新开发者。你能帮我吗?

2 个答案:

答案 0 :(得分:1)

func setCachedVPAIDConfig(key string, j []byte) error {
    p := pool.Get()
    switch p.Err() {
    case nil:
        _, err := p.Do("SET", key, j)
        p.Close()
        return err
    default:
        p.Close()
        return p.Err()
    }
}

func getCachedVPAIDConfig(key string) ([]byte, error) {
    p := pool.Get()
    switch p.Err() {
    case nil:
        item, err := redis.Bytes(p.Do("GET", key))
        p.Close()
        return item, err
    default:
        p.Close()
        return nil, p.Err()
    }
}

     try {
            //set time in mili
            Thread.sleep(3000);

        }catch (Exception e){
            e.printStackTrace();
        }

答案 1 :(得分:1)

onReceive功能

Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable(){
    @Override
    public void run() {
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
            String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Log.v("DialBroadcast Receiver","Number is: "+number);
        }
    }
}, 2000);    // 2000 for two seconds in milis