Languages

Menu
Sites
Language
How get body of sms message?

Hello.

I`m working with my first web-app for tizen and can`t find out how correctly get sms message body. Try to do it as this:

//Initialize function
var init = function () {
    console.log("init() called");

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });    
};


$(document).ready(init);

var MyApp = {};

var smsService;
//Define the success callback.
var messageSentCallback = function(recipients) {
  console.log("Message sent successfully to " + recipients.length + " recipients.");
}

// Define the error callback.
function errorCallback(err) {
  console.log(err.name + " error: " + err.message);
}
    
// Define success callback
function successCallback() {
  console.log("Messages were updated");
}

//Define success callback
function loadMessageBody(message) {
    console.log ("body for message: " + message.subject + "from: " + message.from + "loaded.");
}

function messageArrayCB(messages) {
    console.log('Messages: ' + messages.length);
    for (var message in messages) {
    try{
            MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
        }catch(ex) {
            console.log("Get exception: " + ex.name + ":" + ex.message);
        }
    } 
} 

function serviceListCB(services) { 

    MyApp.smsService = services[0]; 
    MyApp.smsService.messageStorage.findMessages( 
    new tizen.AttributeFilter("type", "EXACTLY", "messaging.sms"), messageArrayCB); 
} 

console.log("run"); 
tizen.messaging.getMessageServices("messaging.sms", serviceListCB, errorCallback);

But I get such output om console in web simalator:

run main.js:88
init() called main.js:4
Messages: 10 main.js:50
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58
Get exception: NotFoundError:An attempt is made to reference a Node in a context where it does not exist. main.js:58

 

So I have a problem at call of loadMessageBody, cuase message with error comes from this code:

try{
            MyApp.smsService.loadMessageBody(message, loadMessageBody, errorCallback);
        }catch(ex) {
            console.log("Get exception: " + ex.name + ":" + ex.message);
        }

App has rights for read and write message. What`s going wrong?

Edited by: Sphinks on 16 Nov, 2013

Responses

1 Replies
konduri sai swathi

Hi,

Try the below code :

tizen.messaging.getMessageServices("messaging.sms", serviceListCB, errorCallback);
    var service=null;
	function serviceListCB(service) {
		console.log("---------------------------------------------") ;
		if (service.length > 0) {
			console.log("in serviceList"+service.length);
			service[0].messageStorage.findMessages(new tizen.AttributeFilter("type", "EXACTLY", "messaging.sms"),messageQueryCallback);
		}
		else
			console.log("--------");
	}

	function errorCallback(error) {
		console.log("Cannot load message body" + error.message);
	}
	function messageQueryCallback(messages) {
		console.log("no. of messages-----"+messages.length);

		for (var i=0; i<messages.length; i++) {
			var message = messages[i];
			console.log("message id----"+messages[i].id);
			if (message.body.loaded && message.folderId==1) 
			{
				console.log("Message Body is ----- "+message.body.plainBody);
				console.log("Message is From ------- "+ message.from);
				console.log("Is Message Read? ------- "+message.isRead);
				console.log("Message Type is ----- "+message.type);
				console.log("Message Time ------ "+message.timestamp);
				if(!message.isRead){
					console.log("isRead IF----");
				}
			}
		}
	}