Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

public class Main {
    public static void sendSMS(String phoneNo, String message, Context context) {
        Log.i("Sending SMS to " + phoneNo, "");

        try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo, null, message, null, null);
            Toast.makeText(context, "SMS sent to " + phoneNo, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(context, "SMS sending failed to " + phoneNo, Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }

    public static void sendSMS(String phoneNo, String message) {
        Log.i("Sending SMS to " + phoneNo, "");

        try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo, null, message, null, null);

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}