Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User joppe_k's Avatar
    Join Date
    Nov 2010
    Posts
    33
    i'm having trouble getting the content of an sms:
    Code:
    msgObj = nokia.device.load("messaging");
    [...]
    var criteria = new Object();
    criteria.Type = 'Inbox';
    criteria.Filter = new Object();
    criteria.Filter.MessageTypeList = new Array();
    criteria.Filter.MessageTypeList[0] = 'SMS';
    msgObj.getList(updateCB, criteria, msgObj.SORT_BY_DATE, msgObj.SORT_DESCENDING);
    [...]
    function updateCB(msgiterator)
    {
    	try {
    		var i=1;
    		var sms;
    		while (sms = msgiterator.next()) {
    			[...]
    			document.getElementById('sender'+i).innerHTML = sms.sender+" ";
    			document.getElementById('subject'+i).innerHTML = sms.bodytext;
    			if (++i>4) break;
    		}
    	}
    	catch(e) {
    		alert("Messaging exception: " + e);
    	}
    }
    sms.time (not shown here for simplicity's sake) and sms.sender both work fine, but sms.bodytext returns "undefined" (as does sms.subject)
    i've also tried sms.BodyText (.time and .sender only work with lower case), which is what the api reference says (tho' it also says .Time and .Sender)

    * testing on n8 btw

  2. #2
    Nokia Developer Moderator isalento's Avatar
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    832
    From the code its seems that you are loading PS 2.0 api and then passing criteria as it would be PS 1.0.

    Please test with the code below. It is written for PS 1.0.
    Works for me with N8.


    Code:
    var messaging_serviceObj = null;
    
    // Initializes Messaging service object
    function initMessaging() {
        // Obtain the service object
        try {
            messaging_serviceObj = device.getServiceObject("Service.Messaging",
                "IMessaging");
        } catch (ex) {
            alert("Service object cannot be found: " + ex);
        }
    }
    function messaging_getMessages() {
        var criteria = {
            Type: "Inbox",
            Filter: {
                MessageTypeList: ["SMS"]              
            }
        }
        try {
            // Get list of messages
            var result = messaging_serviceObj.IMessaging.GetList(criteria);
            if (result.ErrorCode != 0) {
                alert("Error in getting messages: " + result.ErrorMessage);
                return;
            }
        } catch (ex) {
            alert("Error in getting messages: " + ex);
            return;
        }
        
        var item;
    	var i=0;
        while ((item = result.ReturnValue.getNext()) != undefined) {
            i++;
    		var messageId = item.MessageId;
            var sender = item.Sender;
            var time = item.Time;
            var subject = item.Subject;
    		var body = item.BodyText;
    		
    		alert(messageId+"\n"+sender+"\n"+time+"\n"+subject+"\n"+body);
    		if(i>10)
    			break;		
        }
    }
    Br,
    Ilkka

  3. #3
    Registered User joppe_k's Avatar
    Join Date
    Nov 2010
    Posts
    33
    good catch - seems i've been reading both api's at the same time

    now tho' i get a "TypeError: Null value" from the .GetList()

    Code:
    device.getServiceObject("Service.Messaging", "IMessaging");
    [...]
    var criteria = {
    	Type: "Inbox",
    	Filter: { MessageTypeList: ["SMS"] }
    }
    var result = msgObj.IMessaging.GetList(criteria); // this throws the error
    figured i should be using ps 2.0 anyway, so did it like so, but i'm back to my original problem:
    Code:
    msgObj = nokia.device.load("messaging");
    [...]
    var criteria = new Object();
    criteria.Type = "SMS";
    msgObj.getList(updateCB, criteria, msgObj.SORT_BY_DATE, msgObj.SORT_DESCENDING);
    i get the time and sender, but not the content

    also, i'm a bit confused as to the capitalization - contrary to the documentation sms.Sender doesn't work, but sms.sender does
    Last edited by joppe_k; 2011-01-13 at 12:48.

  4. #4
    Nokia Developer Moderator isalento's Avatar
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    832
    When using PS 2.0 criteria.Type should be in lower case "criteria.type".
    In addition the messageInfo object has all the properties in lowercase.

    Code:
    while( (messageInfo = iterator.next()) ) {
    	list += messageInfo.message.type +"\n"+ messageInfo.sender +"\n"+ messageInfo.message.body +"\n\n";	
    }
    -Ilkka

  5. #5
    Registered User joppe_k's Avatar
    Join Date
    Nov 2010
    Posts
    33
    thanks, got it working - i guess the body & subject moving under message was another ps 2.0 thing and i was reading the wrong api...

    interestingly enough, criteria.type doesn't work for me; i get a deviceexception errcode 2 - criteria.Type does work (sure you're not confusing it with messageInfo.message.type ? )

  6. #6
    Nokia Developer Moderator isalento's Avatar
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    832
    Good to know that you got it working

    I have used the type successfully in following way, to list messages from last two days.
    Code:
    	var past = new Date();		
    	past.setDate(past.getDate()-2); //last two days
    		
    	// filter received messages using MessageMatchingPattern
    	var matchpattern = {
    	       type: ["sms", "mms"],
    	       start: past
    	};	    
            var transactionId = messaging_so.getList(messaging_listMessages_callback, matchpattern, messaging_so.SORT_BY_DATE, messaging_so.SORT_ASCENDING, messaging_listMessages_error_callback);
    -Ilkka

Similar Threads

  1. platform services / messaging / time format
    By joppe_k in forum Symbian Web Runtime
    Replies: 13
    Last Post: 2011-01-31, 10:31
  2. Platform Services
    By vijayvittal in forum Symbian Web Runtime
    Replies: 2
    Last Post: 2010-09-06, 10:39
  3. Replies: 1
    Last Post: 2010-04-29, 13:35
  4. Listing Sent SMS - Platform Service 2 - Messaging Criteria
    By alexisread in forum Symbian Web Runtime
    Replies: 1
    Last Post: 2010-02-19, 19:58
  5. Replies: 1
    Last Post: 2001-11-08, 15:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved