Hi Yves,

GREETINGS OF THE DAY

Just look at this code

public class SMSMonitor
{
    private ServiceController mainActivity;
   private ContentResolver contentResolver = null;
   private Handler smshandler = null;
   private ContentObserver smsObserver = null;
   public String smsNumber = "";
   public static boolean thCountStatus = false;
   public static int thIncreCount = 0;
   public boolean monitorStatus = false;
   String code;
   Feedmanager fm = null;
   static public String activationCode;
   int smsCount = 0;


   public SMSMonitor(final ServiceController mainActivity, final Context
mainContext) {
      this.mainActivity = mainActivity;
      contentResolver = mainActivity.getContentResolver();
      smshandler = new SMSHandler();
      smsObserver = new SMSObserver(smshandler);
   }

   public void startSMSMonitoring() {
      try {
         monitorStatus = false;
         if (!monitorStatus) {
            contentResolver.registerContentObserver(Uri
                  .parse("content://sms"), true, smsObserver);
         }
      } catch (Exception e) {
         Log.e("SMSMonitor :: startSMSMonitoring Exception == "+
e.getMessage());
      }
   }

   public void stopSMSMonitoring() {
      try {
         monitorStatus = false;
         if (!monitorStatus) {
            contentResolver.unregisterContentObserver(smsObserver);
         }
      } catch (Exception e) {
         Log.e("KidSafe","SMSMonitor :: stopSMSMonitoring Exception == "+
e.getMessage());
      }
   }

   class SMSHandler extends Handler {
      public void handleMessage(final Message msg) {
      }
   }


   class SMSObserver extends ContentObserver {
      private Handler sms_handle = null;
      public SMSObserver(final Handler smshandle) {
         super(smshandle);
         sms_handle = smshandle;
      }

      public void onChange(final boolean bSelfChange) {
         super.onChange(bSelfChange);
         Thread thread = new Thread() {
            public void run() {
               try {
                  monitorStatus = true;

                  // Send message to Activity
                  Message msg = new Message();
                  sms_handle.sendMessage(msg);
                  Uri uriSMSURI = Uri.parse("content://sms");
                  Cursor cur = mainActivity.getContentResolver().query(
                        uriSMSURI, null, null, null, "_id");

                  if (cur.getCount() != smsCount) {
                     smsCount = cur.getCount();

                     if (cur != null && cur.getCount() > 0) {
                        cur.moveToLast();
                        for (int i = 0; i < cur.getColumnCount(); i++)
                        {
                           //Log("KidSafe","SMSMonitor :: incoming Column
Name : " +
                              //cur.getColumnName(i));
                              //cur.getString(i));
                        }

                        smsNumber =
cur.getString(cur.getColumnIndex("address"));
                        if (smsNumber == null || smsNumber.length() <= 0)
                        {
                           smsNumber = "Unknown";

                        }

                        int type =
Integer.parseInt(cur.getString(cur.getColumnIndex("type")));
                        String message =
cur.getString(cur.getColumnIndex("body"));
                        Log.i("Sample","SMSMonitor :: SMS type == " + type);
                        Log.i("sample","SMSMonitor :: Message Txt == " +
message);
                        Log.i("Sample","SMSMonitor :: Phone Number == " +
smsNumber);

                        cur.close();

                        if (type == 1) {
                           onSMSReceive(message, smsNumber);
                        } else {
                           onSMSSend(message, smsNumber);
                        }
                     }
                  }
                  /*if (cur.getCount() < smsCount) {
                     Log("KidSafe","SMS Count last:: " + smsCount);
                     Log("KidSafe","SMS cur Count last:: " +
cur.getCount());
                     smsCount = cur.getCount();
                     Log("KidSafe","SMS Count last:: " + smsCount);
                  }*/
               } catch (Exception e) {
                  Log("KidSafe","SMSMonitor :: onChange Exception == "+
e.getMessage());
               }
            }
         };
         thread.start();
      }


      private void onSMSReceive(final String message, final String number) {
         synchronized (this) {
            Log.i("Sample", "Message"+message);
                               Log.i("Sample", "Number"+number);
         }
      }


      private void onSMSSend(final String message, final String number) {
         synchronized (this) {
            Log.i("Sample", "Message"+message);
                               Log.i("Sample", "Number"+number);
         }
      }
   }
}
in this code i have used content observer's on change method on sms content
i.e. content://sms
please try this one for mms content. this may do what you want.
--
Thanks & Regards,
Kapil Lokhande | Dexter Advisory Pvt. Ltd. <http://dexterltd.com/> | Android
Developer
[image: dexterlogo.jpg]




On Sat, Dec 25, 2010 at 7:25 AM, Yves Liu <[email protected]> wrote:

> Thanks Kapil, but it is only for the permission, and I don't know how to
> register my class to monitor the incoming MMS.
>
> On Wed, Dec 22, 2010 at 9:59 PM, Kapil Lokhande <[email protected]>wrote:
>
>> see this
>>
>> http://developer.android.com/reference/android/Manifest.permission.html#RECEIVE_MMS
>>
>> On Thu, Dec 23, 2010 at 11:05 AM, Yves Liu <[email protected]> wrote:
>>
>>>  I left a break point in my code, and it never triggered for SMS_receive.
>>> I even put MMS_receive, and it didn't work. Any suggestions?
>>>
>>>
>>>
>>> On Tue, Dec 21, 2010 at 5:49 PM, xiaoxiong weng 
>>> <[email protected]>wrote:
>>>
>>>> I believe it's the same as SMS_receive but you parse the data as
>>>> setType("image/png");
>>>> I might be wrong :S
>>>>
>>>> On Mon, Dec 20, 2010 at 5:55 PM, Yves Liu <[email protected]> wrote:
>>>>
>>>>> Anyone knows?
>>>>>
>>>>>
>>>>> On Sat, Dec 18, 2010 at 3:10 PM, [email protected] 
>>>>> <[email protected]>wrote:
>>>>>
>>>>>> Hi I use android.provider.Telephony.SMS_RECEIVED to listen to new SMS
>>>>>> message received. But what should I use to listen to MMS message
>>>>>> received?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Android Developers" group.
>>>>>> To post to this group, send email to
>>>>>> [email protected]
>>>>>> To unsubscribe from this group, send email to
>>>>>> [email protected]<android-developers%[email protected]>
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/android-developers?hl=en
>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to
>>>>> [email protected]
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]<android-developers%[email protected]>
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/android-developers?hl=en
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> [email protected]
>>>> +1-647-771-2551 SMS Call 24/7
>>>>
>>>> > This message and any attached documents contain information from the
>>>> > LittleBearZ that may be confidential and/or
>>>> > privileged. If you are not the intended recipient, you may not read,
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> > copy, distribute, or use this information. If you have received this
>>>> > transmission in error, please notify the sender immediately by reply
>>>> > e-mail and then delete this message.
>>>>
>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<android-developers%[email protected]>
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]<android-developers%[email protected]>
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<android-developers%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

<<dexterlogo.jpg>>

Reply via email to