Android Twilio音频客户端无法进行任何连接

时间:2017-01-08 14:21:44

标签: android twilio twilio-api

我试图与Twilio Client SDK for android合作,而Twilio服务的经验却很少。

我想在这里实现的是使用Twilio号码从应用程序拨打语音电话。

这是我的客户端实现

key

}

在我的TwiMl应用程序中,我有以下语音请求网址public class AudioCallActivity extends AppCompatActivity implements Twilio.InitListener, View.OnClickListener { private static final int MIC_PERMISSION_REQUEST_CODE = 1; private CoordinatorLayout coordinatorLayout; private String contact; private String name; private String profile_pic; private ImageView profile; private TextView user; private TextView timer; private Device device; private Connection connection; private String TAG = AudioCallActivity.this.getClass().getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_audio_call); if (ActivityCompat.checkSelfPermission(AudioCallActivity.this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AudioCallActivity.this, Manifest.permission.MODIFY_AUDIO_SETTINGS) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(AudioCallActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, MIC_PERMISSION_REQUEST_CODE); ActivityCompat.requestPermissions(AudioCallActivity.this, new String[]{Manifest.permission.MODIFY_AUDIO_SETTINGS}, 2); } if (getIntent() != null) { contact = getIntent().getStringExtra("contact").trim(); patient_name = getIntent().getStringExtra("name"); profile_pic = getIntent().getStringExtra("profile_pic").trim(); loadUI(); } else AudioCallActivity.this.finish(); if (!Twilio.isInitialized()) Twilio.initialize(getApplicationContext(), this); coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorlayout); } private void loadUI() { profile = (ImageView) findViewById(R.id.profile_pic); ((Button) findViewById(R.id.end_call)).setOnClickListener(this); user = (TextView) findViewById(R.id.userName); timer = (TextView) findViewById(R.id.timer); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.end_call: if (connection != null) connection.disconnect(); device.release(); AudioCallActivity.this.finish(); break; } } @Override public void onInitialized() { user.setText("Calling " + name); new GlideOperations(getApplicationContext(), profile).glideImages(profile_pic); NetworkManager.getInstance(getApplicationContext()).StringRequest(TAG, new HashMap<String, String>(), AppConfig.CAPABILITY_TOKEN, new VolleyResponse<String>() { @Override public void success(String response) { if (response != null && !response.isEmpty()) { device = Twilio.createDevice(response, null); HashMap<String, String> param = new HashMap<>(); param.put("PhoneNumber", "XXXXXXXXXX"); if (connection == null) { connection = device.connect(param, new ConnectionListener() { @Override public void onConnecting(Connection connection) { Log.d(TAG, "Connecting..."); } @Override public void onConnected(Connection connection) { timer.setVisibility(View.VISIBLE); Log.d(TAG, "Connected"); } @Override public void onDisconnected(Connection connection) { Log.d(TAG, "Disconnected"); } @Override public void onDisconnected(Connection connection, int i, String s) { } }); } } } @Override public void error(VolleyError error) { Log.d(TAG, "VOLLEY ERROR"); } }, Request.Method.POST); } @Override public void onError(Exception e) { Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == MIC_PERMISSION_REQUEST_CODE && resultCode != RESULT_OK) { Snackbar snackbar = Snackbar.make(coordinatorLayout, "Lyphe Call need the following permission to operate.", Snackbar.LENGTH_LONG); snackbar.show(); } }

这是相同

的服务器端脚本
{xyz.com}/outgoing

请让我知道我在哪里弄错了。 TIA

0 个答案:

没有答案