Sending an SMS message

To send a message, we will create a POST endpoint that takes a Message object, which we'll then pull apart and pass to Android's telephony APIs.

 @POST @Path("conversations") public Response sendMessage(Message message) throws InterruptedException { final SmsManager sms = SmsManager.getDefault(); final ArrayList<String> parts = sms.divideMessage(message.getBody()); final CountDownLatch sentLatch = new CountDownLatch(parts.size()); final AtomicInteger statusCode = new AtomicInteger( Response.Status.CREATED.getStatusCode()); final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (getResultCode() != Activity.RESULT_OK) { statusCode.set( Response.Status.INTERNAL_SERVER_ERROR ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.