Example of Twilio in Android Studio [closed]

孤街醉人 提交于 2019-12-24 01:10:47

问题


Well,I am getting difficulty finding out an example of Twilio message sending in Android.Could anybody site me an example along with what jar files do I need to import?


回答1:


Twilio developer evangelist here.

I think the reason you're having trouble finding that, is because sending messages on Android directly with Twilio is usually not recommended.

That is because to send an SMS message with Twilio, you will need an application Sid and an Auth Token, which are your credentials with Twilio. If you were to use the Java Library to send this SMS, it would mean your authentication keys are packaged with your application, which also means anyone who decompiles your application gets access to those keys and can use your account to do the same.

The way we usually recommend doing that is by creating a backend application, and then making an HTTP request to it. This way your keys live in the backend application, and you can configure it however you like, so even if you wanted the message to come from the device itself, you could just pass that to your backend application.

In this page you will find how to send SMS messages using Twilio in all the most common programming languages.

Once you have one of those deployed, all you need to do is make an HTTP request to it from your app. There are lots of different libraries to help you doing that, but my favourite is Square's OkHttp.

Here's how you could make an HTTP request to your backend app using it:

OkHttpClient client = new OkHttpClient();

String run(String url) throws IOException {
  Request request = new Request.Builder()
      .url(url)
      .build();

  Response response = client.newCall(request).execute();
  return response.body().string();
}

Hope this helps you!



来源:https://stackoverflow.com/questions/37051380/example-of-twilio-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!