It is very easy to send an sms. I just added a few lines of code to send an sms. Check out this example that sends an sms with a date stamp. Just import android.telephony..., and then the line sm.sendTextMessage(number, null, text+now+" "+number, null, null); will send the message. One important thing: You have to open Android->set permissions and check "send sms".
- /**
- * Load and Display
- *
- * Images can be loaded and displayed to the screen at their actual size
- * or any other size.
- * Some lines added to send sms
- */
- import android.telephony.gsm.SmsManager;
- import java.util.Date;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
-
- PImage a; // Declare variable "a" of type PImage
- boolean first=true;
- float scale=1.0;
- //sms setup
- SmsManager sm = SmsManager.getDefault();
- String number = "5554";
- //number can be a phone number if run on device or port number of
- //a second emulator if run on emulator. one emulator can send to the second
- //emulator
- String text = "Yay! Sms sent with processing. ";
- void setup() {
- size(200, 200);
- // The file "jelly.jpg" must be in the data folder
- // of the current sketch to load successfully
- a = loadImage("jelly.jpg"); // Load the image into the program
- }
- void draw() {
- // Displays the image at its actual size at point (0,0)
- if (first){
- image(a, 0, 0, a.width*scale, a.height*scale);
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- Date date = new Date();
- String now=dateFormat.format(date);
- sm.sendTextMessage(number, null, text+now+" ", null, null);
- first=false;
- }
- delay(500);
- scale=random(0.05,0.95);
- image(a, 0, 0, a.width*scale, a.height*scale);
- }