smsGetMessageIds

postado em 6 de jun de 2012 16:34 por Silvio Garbes
smsGetMessageIds(
 
Boolean unreadOnly,
 
String folder[optional, default inbox])

Returns a List of all message IDs.

Exemplo

<?php
/* @author: Nicolas B. <amd3002[at]gmail[dot]com>

Find more scripts on my blog : http://boutetnico.wordpress.com/

*/
require_once('Android.php');
$droid = new Android();

$DEFAULT_LIMIT = 10; /* Default SMS list length */
$todo = 'init';

/* Main loop */
while (1)
{
   switch($todo)
   {
      case 'init':
         /* Main menu */
         $droid->dialogCreateAlert('PFA SMS Infos');
         $droid->dialogSetPositiveButtonText('Show infos!');
         $droid->dialogSetNegativeButtonText('Exit');
         $droid->dialogShow();
         $choice = $droid->dialogGetResponse();/* We wait until user press a button */

         /* We test user choice */
         switch($choice['result']->which)
         {
            case 'positive' :

               /* We get number of SMS */
               $unread_SMS = $droid->smsGetMessageCount(1);
               $total_SMS = $droid->smsGetMessageCount(0);

               /* We extract values */
               $unread_SMS_result = $unread_SMS['result'];
               $total_SMS_result = $total_SMS['result'];

               /* SubMenu */
               $droid->dialogCreateAlert('PFA SMS Infos');
               $table[0] = 'Unread only : ' . $unread_SMS_result;
               $table[1] = 'Read & unread : ' . $total_SMS_result;

               $droid->dialogSetSingleChoiceItems($table);
               $droid->dialogSetPositiveButtonText('Show list');
               $droid->dialogSetNegativeButtonText('Exit');
               $droid->dialogShow();
               $response = $droid->dialogGetResponse();/* We wait until user press 'Back' or an entry in the list */

               switch($response['result']->which)
               {
                  case 'positive':/* Show list case */
                     $selected = $droid->dialogGetSelectedItems();

                     switch($selected['result'][0])/* Bi - dimensionnal array, 0 because it's first and unique value (SingleChoiceItems) */
                     {
                        case '0': /* Unread SMS only */
                           $ids = $droid->smsGetMessageIds(1);/* Retrieves a list of SMS's ids */
                           $amount = $unread_SMS_result;/* We need this in order to know how many SMS we will have to display */
                           break;

                        default: /* Everything else */
                           $ids = $droid->smsGetMessageIds(0);/* Retrieves a list of SMS's ids */
                           $amount = $total_SMS_result;/* We need this in order to know how many SMS we will have to display */
                           break;
                     }

                     /* If there are more SMS to display than the DEFAULT_LIMIT value, we ask user to input a limit */
                     if ($amount > $DEFAULT_LIMIT)
                     {
                        $howMany = $droid->getInput('PFA SMS Infos', 'How many SMS do you want to display [default = ' . $DEFAULT_LIMIT . '] ?');
                        if (!empty($howMany['result']))
                        {
                           $limit = $howMany['result'];
                        }
                        else
                        {
                           $limit = $DEFAULT_LIMIT;
                        }
                     }
                     else
                     {
                        $limit = $DEFAULT_LIMIT;
                     }

                     /* Infos we wanna extract from each SMS */
                     $attributes = array('body');

                     /* For each SMS id, we retrieve its content (body) */
                     $SMS_list = array();
                     $i = 0;
                     foreach($ids['result'] as $v)
                     {
                        $SMS = $droid->smsGetMessageById($v, $attributes);
                        $SMS_list[$i] = $SMS['result']->body;
                        $i++;

                        /* We display only a limited number of SMS */
                        if ($i >= $limit)
                           break;
                     }

                     /* We check if there is at least 1 SMS, if not we put a message in the array */
                     if (empty($SMS_list))
                        $SMS_list[0] = 'Nothing...';

                     $droid->dialogCreateAlert('PFA SMS Infos');
                     $droid->dialogSetItems($SMS_list);
                     $droid->dialogSetNeutralButtonText('Back');
                     $droid->dialogShow();
                     $droid->dialogGetResponse();/* We wait until user press 'Back' or an entry in the list */
                     break;

                  default :/* Exit case */
                     $todo = 'exit';
                     break;
               }
               break;

            default :/* Exit case */
               $todo = 'exit';
               break;
         }
         break;

      case 'exit'://Exit case
         $droid->exit();
         exit(1);
         break;
   }
}
/* End of file */
?>
Comments