问题
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