am creating an android app for school which will need to send text messages. I have had twilio recommended by several people so I decided to go with it. Following this tutorial: https://www.twilio.com/blog/2016/05/how-to-send-an-sms-from-android.html , with my own android app and the one including I am getting a 404 when post is called (seen through ngrok). I am at a complete loss, still new to android. The backend gives the following message through intellij: 8810 [qtp649044888-15] INFO spark.http.matching.MatcherFilter - The requested route [/] has not been mapped in Spark for Accept: [null]
Account IDs, addresses, phone numbers, etc. replaced with x's Backend:
//Heroku assigns different port each time, hence reading it from process.
ProcessBuilder process = new ProcessBuilder();
Integer port;
if (process.environment().get("PORT") != null) {
port = Integer.parseInt(process.environment().get("PORT"));
} else {
port = 4567;
}
Spark.port(port);
get("/", (req, res) -> "Hello, World");
TwilioRestClient client = new TwilioRestClient.Builder(System.getenv("ACxxxxxxx72279fb226f0dd162c869ce1e"), System.getenv("xxxxxxxc324a89155b93b5af26393297")).build();
post("/sms", (req, res) -> {
String body = req.queryParams("Body");
String to = req.queryParams("To");
String from = System.getenv("216450xxxx");
Message message = new MessageCreator(
new PhoneNumber(to),
new PhoneNumber(from),
body).create(client);
return message.getSid();
});
App- post method
Call post(String url, Callback callback) throws IOException {
RequestBody formBody = new FormBody.Builder().add("To", "609420xxxx").add("Body", "TEST").build();
Request request = new Request.Builder().url(url).post(formBody).build();
Call response = mClient.newCall(request);
response.enqueue(callback);
Log.d("CALL: ", response.toString()+ " " + callback.toString());
return response;
}
App post method on button:
emailButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
post("http://xxxxxxxx.ngrok.io", new Callback(){
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"SMS Sent!",Toast.LENGTH_SHORT).show();
}
});
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
});
This should be sending a text to my number (verified on twilio account), but I get nothing. The toast does appear saying the text has been sent.