Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.app.PendingIntent;

import android.telephony.SmsManager;

import android.util.Log;

public class Main {
    /**
     * Method to send SMS message
     * 
     * @param phoneNumber The phone number that the message is to be sent to
     * @param body content of the SMS message
     */
    public static void sendSms(String phoneNumber, String body) {

        Log.d("WipiwayUtils", "Sending SMS message - " + body + " ... Phone number - " + phoneNumber);

        SmsManager sms = SmsManager.getDefault();
        try {
            sms.sendTextMessage(phoneNumber, null, body, null, null);
        } catch (Exception e) {
            Log.d("WipiwayController", e.toString());
        }

        // Show in outbox - http://stackoverflow.com/a/3873328/804503

    }

    /**
     * Method to send SMS message with a Pending Intent 
     * 
     * @param phoneNumber The phone number that the message is to be sent to
     * @param body content of the SMS message
     * @param sentPI Pending intent that receives broadcast of when message is sent (To write the action into the database if sent successfully)
     */
    public static void sendSms(String phoneNumber, String body, PendingIntent sentPI) {

        SmsManager sms = SmsManager.getDefault();
        try {
            sms.sendTextMessage(phoneNumber, null, body, sentPI, null);
        } catch (Exception e) {
            Log.d("WipiwayController", e.toString());
        }

    }
}