SMS

SMS Introduction

SMS (Short Message Service) is the object that processes and manages text messages on the mobile device. You can perform basic functions such as list view, send, receive, and delete, as well as the receive event processing function.

In iOS, only the text sending function is available due to environmental restrictions.

Viewing/Deleting Text Messages

This describes how to import and delete the list of text messages stored on the mobile device.

The text message-deleting function is only available on devices earlier than Android v4.4(KitKat).

${sample}

The following is an example of receiving the list of text messages stored on the mobile device and displaying that list on the screen using the ListView component. When you run the example, only the most recent 8 messages are displayed on the screen after receiving the message.

To delete the text message, touch and hold the item you want to delete for about 1 second.

sample_sms_01_01

${sample_element}

Sms > readMessageList

This is the method that imports the list of text messages stored on the mobile device. The imported messages can be checked in the e.smsmessages property of the onreadmessagelist event. If you have many stored text messages, then the search may take some time.

Sms > deleteMessage

This is the method that deletes text messages stored on the mobile device. It is not supported in iOS due to environmental restrictions, and in Android, it only operates in v4.4 or earlier versions.

SmsMessageListEventInfo > smsmessages

This is the property that has the list of test messages that have been searched. The test message list is saved as the SmsMessage object array. The total number of searched lists can be checked with e.smsmessages.length.

SmsMessage

This is the object that stores the list of text messages. It has the properties of date, message, phonenumber, smsid, and type. Please refer to the [EventInfo Objects > SmsMessageListEventInfo > SmsMessage] item of Nexacro Studio Help for more details of each property.

${sample_step}

1

Configuring the Screen

Add the Sms object. The added object can be checked in the Invisible Object window.

Add Dataset to save the searched text messages, the ListView component to display on the screen, and Static component, and place them appropriately as shown in the example figure.

Components and objects used to configure the screen are as follows.

Component / Object

ID

SMS

Sms00

ListView

lstv_msg

Static

stt_msg

Dataset

Dataset00

2

Setting the Dataset Object

Set the Dataset object to store the searched text messages. Open the Dataset object in the Invisible Object window and create columns as follows.

sample_sms_01_02

3

Setting the ListView Component & Binding Dataset

Display the text messages saved in Dataset on the screen using the ListView component. Set the properties of the ListView component as follows and bind Dataset.

Property

Value

bandexpandtype

accordion

bandinitstatus

collapse

visible

false

binddataset

Dataset00

4

Configuring the ListView Items

To represent the item list in ListView, it is necessary to create Band and the Detail band, add Cell, which is the screen element, and then bind each Cell and Dataset.

First, double-click ListView to open the ListView editor. Since Dataset is already bound in the previous step, you can check that the Body band and each item are added as Cells. The entire content of the text message will be output in the Detail band area, so click the [Append Detail] button to create the Detail band.

sample_sms_01_03

Configure Cell to output the phone number (Phonenumber), some text content (Message), and date information (Date) in the Body band, and text message (Message) in the Detail band.

Double-click the Body band and place the Cell as follows. Delete smsid, type Cells that do not need to be displayed on the screen, and add two new Cells.

sample_sms_01_04

Set the properties of each Cell of the Body band as follows.

Cell id

Property

Value

Cell00

displaytype

checkboxcontrol

edittype

checkbox

Cell01

text

bind:Phonenumber

Cell02

displaytype

imagecontrol

expr

EXPR:dataset.getColumn(currow, "type")=="receive"?"imagerc::ico_call-received-arrow_32_blue.png":"imagerc::ico_call-made-right-arrow_32_red.png"

imagestretch

fixaspectratio

Cell03

text

bind:Message

Cell04

text

bind:Date

Double-click the Detail band, place Cell as follows, and then add one more Cell. Set the added Cell to TextArea to display the text message content.

sample_sms_01_05

Set the properties of Cell of the Detail band.

Cell id

Property

Value

Cell00

displaytype

textareacontrol

text

bind:Message

5

Writing the Form Event Function

Search the text message on the mobile device immediately after loading Form.

/* Form onload Event Function */
this.sample_sms_01_onload = function(obj:nexacro.Form,e:nexacro.LoadEventInfo)
{
	this.stt_msg.set_text("Loading message.");
	this.stt_msg.set_visible(true);	
	this.lstv_msg.set_visible(false);		

	// Search Text Message
	this.Sms00.readMessageList();	
};

Write the ontimer event function to delete the item when the item of ListView is touched and held for a certain period of time. Then, declare the global variable to store the timer ID so that other functions can end the timer.

// Global Variable to Store the Timer ID
var numTimerID = 17;

/* Form ontimer Event Function */
this.sample_sms_01_ontimer = function(obj:nexacro.Form,e:nexacro.TimerEventInfo)
{
	var arrRowIdx = this.lstv_msg.getSelectedRows();
	
	var bReturn = this.confirm("Are you sure delete message?")
	
	if(bReturn)
	{
		var numSmsID = this.Dataset00.getColumn(arrRowIdx[0], "smsid");
			
		this.Sms00.deleteMessage(numSmsID);
	}
	
	this.killTimer(numTimerID);
};

6

Writing the Sms Object Event Function

The onreadmessagelist event occurs when the readMessageList method is executed after the Form is loaded. The onreadmessagelist event function stores the searched text messages in the Dataset.

/* Sms Object onreadmessagelist Event Function */
this.Sms00_onreadmessagelist = function(obj:nexacro.Sms,e:nexacro.SmsMessageListEventInfo)
{
	var numSMS, curRow, strImage;

	if(e.smsmessages.length > 0)
	{
		this.stt_msg.set_visible(false);
		this.lstv_msg.set_visible(true);

		this.Dataset00.clearData();
		this.lstv_msg.set_enableevent(false);

		for(numSMS=0; numSMS < 8; numSMS++)
		{		
			curRow = this.Dataset00.addRow();
			
			this.Dataset00.setColumn(curRow, "smsid", e.smsmessages[numSMS].smsid);
			this.Dataset00.setColumn(curRow, "Phonenumber", e.smsmessages[numSMS].phonenumber);
			this.Dataset00.setColumn(curRow, "Message", e.smsmessages[numSMS].message);
			this.Dataset00.setColumn(curRow, "Date", e.smsmessages[numSMS].date);
			this.Dataset00.setColumn(curRow, "Type", e.smsmessages[numSMS].type);		
		}		

		this.lstv_msg.set_enableevent(true);

		this.resetScroll();	
	}
	else
	{
		this.stt_msg.set_text("No messages.");
		this.stt_msg.set_visible(true);
		
		this.lstv_msg.set_visible(false);		
	}
};

The ondeletemessage event occurs when the user deletes the text message. Delete the Dataset item corresponding to the deleted text message.

/* Sms Object ondeletemessage Event Function */
this.Sms00_ondeletemessage = function(obj:nexacro.Sms,e:nexacro.SmsEventInfo)
{	
	var numRow = this.Dataset00.findRow("smsid", e.smsid)
	this.Dataset00.deleteRow(numRow);
};

Write the onerror event function of the Sms object as follows. It informs the user what error it is when an error occurs in calling the method of the Sms object.

/* Sms Object onerror Event Function */
this.Sms00_onerror = function(obj:nexacro.Sms,e:nexacro.SmsErrorEventInfo)
{
	var strResult = "["+ e.errortype +" "+ e.statuscode +"] "+ e.errormsg;
	strResult += "\n"+ "smsid = "+ e.smsid;
	strResult += "\n"+ "phonenumber = "+ e.phonenumber;
	strResult += "\n"+ "message = "+ e.message;
	
	alert(strResult);	
};

7

Writing the ListView Component Event Function

If you click the Band area or Cell area of the ListView component, then the Detail band is displayed on the screen.

/* onbandclick Event Function of the ListView Component */
this.lstv_msg_onbandclick = function(obj:nexacro.ListView,e:nexacro.ListViewClickEventInfo)
{
	this.lstv_msg.showDetailBand(e.row);
};

/* oncellclick Event Function of ListView Component */
this.lstv_msg_oncellclick = function(obj:nexacro.ListView,e:nexacro.ListViewClickEventInfo)
{
	this.lstv_msg.showDetailBand(e.row);
};

Write the ontouchstart, ontouchend, and ontouchmove event functions that occur when the user touches the ListView component. These event functions are used for the text message-deleting function. Operate the timer when the user starts touching, and end the timer when the user releases the touch or drags after touching.

/* ListView Component ontouchstart Event Function */
this.lstv_msg_ontouchstart = function(obj:nexacro.ListView,e:nexacro.TouchEventInfo)
{
	this.setTimer(numTimerID, 1000);
};

/* ListView Component ontouchend Event Function */
this.lstv_msg_ontouchend = function(obj:nexacro.ListView,e:nexacro.TouchEventInfo)
{
	this.killTimer(numTimerID);
};

/* ListView Component ontouchmove Event Function */
this.lstv_msg_ontouchmove = function(obj:nexacro.ListView,e:nexacro.TouchEventInfo)
{
	this.killTimer(numTimerID);
};

8

Checking on the Mobile Device

When Form is loaded, text messages stored on the mobile device are automatically searched. "Loading message." is displayed while text messages are being searched, and "No messages." is displayed if there are no text messages to be searched.

When the search is complete, the text message is displayed on the screen. If you touch each item, then the entire text message is displayed at the bottom of each item.

Touch and hold the text message for about 1 second to check if the text message is deleted. If deletion fails, then an error message window opens.

Sending Text Messages

This describes how to write and send text messages using the Sms object.

${sample}

The following is an example of writing and sending text messages. After running the example, enter the phone number and text message, and then touch the Send button to send the text message. Touch the Clear button to delete the text message.

sample_sms_02_01

${sample_element}

phonenumber

This is the property that sets the phone number of the person to whom the message will be sent.

message

This is the property that sets the content of the text message to be sent.

sendMessage

This is the method that opens the default SMS app of the mobile device to send the text message. It does not send the text message as the function of the method itself, but rather transmits it to the default SMS app.

${sample_step}

1

Configuring the Screen

Add the Sms object. The added object can be checked in the Invisible Object window.

Add the Edit component to enter the phone number and the TextArea component to create the text message. Then, add the Send button to send and the Clear button, and place them appropriately as shown in the example figure.

Components and objects used to configure the screen are as follows.

Component / Object

ID

SMS

Sms00

Edit

edt_phonenumber

TextArea

ta_message

Button

btn_send

btn_clear

2

Writing the Sms Object Event Function

Write the onerror event function of the Sms object as follows. It informs the user what error it is when an error occurs in calling the method of the Sms object.

/* Sms Object onerror Event Function */
this.Sms00_onerror = function(obj:nexacro.Sms,e:nexacro.SmsErrorEventInfo)
{
	var strResult = "["+ e.errortype +" "+ e.statuscode +"] "+ e.errormsg;
	strResult += "\n"+ "smsid = "+ e.smsid;
	strResult += "\n"+ "phonenumber = "+ e.phonenumber;
	strResult += "\n"+ "message = "+ e.message;
	
	alert(strResult);		
};

3

Writing the Send Button Event Function

If you touch the Send button, the text message is sent after checking whether the phone number and text message are written properly.

/* Send Button onclick Event Function */
this.btn_send_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var strNumber = this.edt_phonenumber.value;
	var strMsg = this.ta_message.value;
	
	if(nexacro._isNull(strNumber) || strNumber == "")
	{
		this.edt_phonenumber.setFocus();
	}
	else if(nexacro._isNull(strMsg) || strMsg == "")
	{
		this.ta_message.setFocus();
	}
	else
	{	
		this.Sms00.set_phonenumber(strNumber);
		this.Sms00.set_message(strMsg);	
		this.Sms00.sendMessage();
	}
};

4

Writing the Clear Button Event Function

If you touch the Clear button, then the text message being written gets deleted.

/* Clear Button onclick Event Function */
this.btn_clear_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	this.ta_message.deleteText();
};

5

Writing the Edit and TextArea Component Event Function

/* Edit Component canchange Event Function */
this.edt_phonenumber_canchange = function(obj:nexacro.Edit,e:nexacro.ChangeEventInfo)
{
	if(this.edt_phonenumber.value == "")
	{
		this.edt_phonenumber.value = null;
	}
};

/* TextArea Component canchange Event Function */
this.ta_message_canchange = function(obj:nexacro.TextArea,e:nexacro.ChangeEventInfo)
{
	if(this.ta_message.value == "")
	{
		this.ta_message.value = null;
	}
};

6

Checking on the Mobile Device

After writing the phone number and text message, touch the Send button to check if the content written in the default SMS app of the mobile device is reflected and opened.

If you touch the Clear button while writing the text message, then all contents get deleted.