Sending an SMS Text Message

Monkey Targets Forums/Android/Sending an SMS Text Message

cageInfamous(Posted 2012) [#1]
This is how to Send a Text from your android phone:

This is the android file: rophone.android.java
import android.telephony.SmsManager;

class rophone
{
	public static SmsManager SmsM = SmsManager.getDefault();
	static void SendSms(String number, String msg)
	{
		SmsM.sendTextMessage(number, null, msg, null, null);
	}
}


This is the monkey script: rophone.monkey
#If TARGET = "android"

Import mojo
Import "rophone.android.java"

Extern
Function SendSms:Void(number:String, msg:String) = "rophone.SendSms"
Public

#Endif


Here's how to use it:
SendSms("5554748392", "Text")'That's not a real number...


Tested and works. Make sure to add the "SEND_SMS" permission to the AndroidManifest.
I plan on making a small phone library.


Xaron(Posted 2012) [#2]
That's cool, thanks!


Supertino(Posted 2012) [#3]
nice


dave.h(Posted 2012) [#4]
very easy to implement and works great thanks for this.


cageInfamous(Posted 2012) [#5]
Thanks for the positive feedback XD
I hope someone can use it


dave.h(Posted 2012) [#6]
hehe just built a spamming app.Right now to spamtext my enemies


cageInfamous(Posted 2012) [#7]
Awesome! I did the exact same thing haha XD


Amon(Posted 2012) [#8]
Nice!


Midimaster(Posted 2012) [#9]
thank you! I will use this for my current online-game. Now the user can invite friends for playing with him and sending them the Team-Id.

What about writing a list of all possible native android function calls here in forum?


therevills(Posted 2012) [#10]
What about writing a list of all possible native android function calls here in forum?


Here you go:

http://developer.android.com/reference/packages.html

;)


Midimaster(Posted 2012) [#11]
do you think all these functions could be integrated? wow!


therevills(Posted 2012) [#12]
Yes, with enough time and writing the externs, why not :-)


cageInfamous(Posted 2012) [#13]
yeah the externs are pretty awesome. Here's another use which the code is nearly the same. It detects the Language that your android device is set too.

android file: extra.android.java
import java.util.Locale;

class roExtra
{
	public static Locale Loc = Locale.getDefault();
	
	public static String GetLang()
	{
		return Loc.getDisplayLanguage();
	}
}


and here's the Android file:
#If TARGET = "android"
		Import "extra.android.java"
		Extern
			Function GetLang:String() = "roExtra.GetLang"
		Public
#Else
	Function GetLang:String()
		Return ""
	End function
#Endif


It should return a string with the language


Volker(Posted 2013) [#14]
Looks like it's only allowed for one app to send SMS in Android 4.4

"Given the fact that on Android 4.4 KitKat, only one application will be able to receive and send SMS / MMS, Google recommends devs to disable the ability to send new messages when a certain app is not currently selected as default. "

http://news.softpedia.com/news/Google-Details-SMS-Changes-in-Android-4-4-KitKat-Offers-New-APIs-391108.shtml