简体   繁体   English

Twilio Java库到带有build.gradle的android项目中的问题

[英]Problems with twilio java library into android project with build.gradle

I am facing few problems including the twilio library into an android project. 我面临的几个问题包括将twilio库集成到android项目中。 First I included with 首先我包括

 compile group: 'com.twilio.sdk', name: 'twilio', version: '7.4.0'

But I started getting this ill-advised or mistaken problem as mentioned int this SO question 不过,我开始为INT此SO提及得到这个不明智的或错的问题的问题

So, I excluded the javax library with 所以,我排除了javax库

compile (group: 'com.twilio.sdk', name: 'twilio', version: '7.4.0'){
    exclude group: 'javax.xml.bind', module: 'jaxb-api'
}

But then I am getting run time errors complaining that twilio can't make HTTP call because it can't find the NetworkHttpClient 但是然后我遇到了运行时错误,抱怨twilio无法进行HTTP调用,因为它找不到NetworkHttpClient

com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:33)

The dependency chain for twilio library looks like this. twilio库的依赖关系链如下所示。 在此处输入图片说明

Any ideas on how to solve this? 关于如何解决这个问题的任何想法? All I want to do this make a couple of HTTP calls to twilio to make a telephone call in my test and I can very well do this with a simple curl statement, so alternative approaches are welcome as well. 我要做的就是在测试中对twilio进行几个HTTP调用以进行电话呼叫,并且我可以使用简单的curl语句很好地做到这一点,因此也欢迎使用其他方法。

Twilio developer evangelist here. Twilio开发人员布道者在这里。

The Java library is not meant to be used with Android, and as you've seen, when you try to use it, you will end up with networks errors since the library uses a version of Apache HTTP that is not supported by Android. Java库并非旨在与Android一起使用,并且如您所见,当您尝试使用Java库时,由于该库使用了Android不支持的Apache HTTP版本,因此最终会出现网络错误。

Now, back to what you're trying to do, I suggest that instead of trying to make requests to the Twilio API from Android directly, you add a backend server, that way, you just need to make a request to that backend server from your app. 现在,回到您要执行的操作,我建议您添加后端服务器,而不是尝试直接从Android向Twilio API发出请求,那样,您只需从以下位置向该后端服务器发出请求您的应用。 This stops your credentials being visible to anyone who downloads your app. 这会使下载您的应用的任何人都看不到您的凭据。

I described how to send SMS from Android in this blog post , but you should be able to modify it so you can also make telephone calls. 我在此博客文章中介绍了如何从Android发送SMS,但是您应该可以对其进行修改,以便也可以拨打电话。

Then on your app you can do something like: 然后在您的应用上,您可以执行以下操作:

Call post(String url, Callback callback) throws IOException{
    RequestBody formBody = new FormBody.Builder()
            .add("To", mTo.getText().toString())
            .add("Body", mBody.getText().toString())
            .build();
    Request request = new Request.Builder()
            .url(url)
            .post(formBody)
            .build();

If what you're trying to do however is make Voip calls, then you should look at the Twilio Programmable Voice SDK . 但是,如果您要进行的是拨打Voip电话,则应查看Twilio可编程语音SDK The page has examples of how to use it. 该页面包含有关如何使用它的示例。

Hope this helps you! 希望这对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM