Code example for SmsMessage: Receiving Text Messages (SMS)

Methods: getMessageBody, getOriginatingAddress

0
        } 
    } 
 
    private void handleMessage(final SmsMessage msg) {
        if (isPingCommand(getCommandFromMessage(msg))) {
            sendPongReply(msg.getOriginatingAddress());
            abortBroadcast();
        } 
    } 
 
    private static String getCommandFromMessage(final SmsMessage msg) {
        return msg.getMessageBody().trim().toLowerCase();
    } 
 
    private static boolean isPingCommand(final String command) {
        return "ping".equals(command);
    } 
 
    private static void sendPongReply(final String address) {
        SmsManager.getDefault().sendTextMessage(
            address, null, "pong", null, null