1

当使用 Twilio 作为第三方集成从 Twilio 号码到应用程序中的另一个 Twilio 号码进行呼叫时,我在获取传入号码方面做了很多研发工作。

但是我没有收到关于该来电号码的任何信息,我接到了来自另一个 Twilio 号码的电话,设备正在收听来电,但无法识别来电号码,因为我正在使用这种方法connectionCall.IncomingParameterFromKey,它只返回我“从”。

下面是使用 Twilio 集成在应用程序中接收呼叫的代码。

public class Call_Answer extends Activity implements OnClickListener{

String sub_sid="",sub_auth_token="",call_from="";
SharedPreferences sharedPref;
SharedPreferences.Editor prefEdit;
TextView callanswer_btn,callreject_btn;
private Connection connectionCall;
IncomingCall phone;
private Device device;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Method onCreate created by vk hooda on Oct 30, 2012
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.callanswer);


    sharedPrefValues();
    initializeView();

}

private void sharedPrefValues() {
    // Method sharedPrefValues created by vk hooda on Oct 31, 2012


    sharedPref=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefEdit=sharedPref.edit();
    sub_sid=sharedPref.getString(Constant_Variables.using_sub_sid,"");
    sub_auth_token=sharedPref.getString(Constant_Variables.using_sub_auth_token,"");
    call_from=sharedPref.getString(Constant_Variables.using_phone_number, "");

    //Initialize Calls
    phone=new IncomingCall(sub_sid,sub_auth_token,call_from,getApplicationContext());

    //phone=new IncomingCall(Constants.account_SID,Constants.account_Token,Constants.karl_number,getApplicationContext());

}

private void initializeView() {
    // Method initializeView created by vk hooda on Oct 30, 2012

    callanswer_btn=(TextView)findViewById(R.id.callanswer_btn);
    callreject_btn=(TextView)findViewById(R.id.callreject_btn);

    callanswer_btn.setOnClickListener(this);
    callreject_btn.setOnClickListener(this);
}

@Override
public void onNewIntent(Intent intent)
{
    super.onNewIntent(intent);
    setIntent(intent);
}

@Override
public void onResume()
{
    super.onResume();

    Intent intent = getIntent();
    Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
    Connection connection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
    if (device != null && connection != null) {
        intent.removeExtra(Device.EXTRA_DEVICE);
        intent.removeExtra(Device.EXTRA_CONNECTION);
        handleIncomingConnection(device, connection);

        //              ringingPhone(intent);

    }
}

public void handleIncomingConnection(Device inDevice, Connection inConnection)
{
    Log.i("Handle incoming call", "Device received incoming connection");
    connectionCall=inConnection;
    device=inDevice;
    if (connectionCall != null)
    {
        connectionCall.disconnect();
        connectionCall = inConnection;
//          connectionCall.reject();


        Log.i("Blocktimer.blocking_call",""+Blocktimer.blocking_call);

        if(Blocktimer.blocking_call == true)
        {
            connectionCall.reject();
            Blocktimer.blocking_call = false;
        }



        Log.i("connectionIIIIII",""+ connectionCall.IncomingParameterAccountSIDKey);
        Log.i("connectionIIIIII",""+ connectionCall.IncomingParameterAPIVersionKey);
        Log.i("connectionIIIIII",""+ connectionCall.IncomingParameterCallSIDKey);
        Log.i("connectionIIIIII",""+ connectionCall.IncomingParameterFromKey);
        Log.i("connectionIIIIII",""+ connectionCall.IncomingParameterToKey);
        Log.i("connectionIIIIII",""+ connectionCall.hashCode());
        Log.i("connectionIIIIII",""+ connectionCall.CONTENTS_FILE_DESCRIPTOR);
        Log.i("connectionIIIIII",""+ connectionCall.PARCELABLE_WRITE_RETURN_VALUE);
        Log.i("connectionIIIIII",""+ connectionCall.getState());
        Log.i("connectionIIIIII",""+ connectionCall.isIncoming());
        Log.i("connectionIIIIII",""+ connectionCall.isMuted());




        Log.v("Handling Incoming Call","Someone calling you.you have accepted it here.");
    }

}

public void onClick(View v) {
    // Method onClick created by vk hooda on Oct 30, 2012

    if(v==callanswer_btn)
    {

        if (connectionCall != null)
        { 
            connectionCall.accept();
            Log.i("connectionaccept",""+ connectionCall.getState());
            Log.v("calling answer","Conversation start.....");
        }
    }

    if(v==callreject_btn)
    {
        //connectionCall.disconnect();
        Log.v("calling disconnect","Conversation disconnect.....");

        if (connectionCall != null)
        { 
            connectionCall.disconnect();
            Log.i("connectionReject",""+ connectionCall.getState());
            connectionCall=null;

            Log.v("Disconnect","Disconnecting in finalize method");
        }
        if (device != null)
        {
            Log.v("Disconnect","Release in finalize method");
            device.release();
            device=null;
        }

        finish();
    }   
}

}

4

1 回答 1

0

我也遇到了同样的问题,我通过使用此代码进行纠正, connection.IncomingParameterFromKey只会返回您需要将该名称传递给连接参数的参数名称。

代码 :

connection.getParameters().get(connection.IncomingParameterFromKey).replace("%2B", "");

于 2015-01-14T07:06:03.823 回答