tags:

views:

1768

answers:

3

Hi Everyone,

I was wondering if anyone knew anything about programmatically getting the sms messages off of your phone's sim card on an android platform. I would like to write a program that allows you to save either individual messages or entire threads to the sd card, but after looking around for a bit, I have discovered that google decided to take out that api from the current android sdk. I saw in a few places that there are hidden apis for this, but no one knew what they were or how to use them.

Any help is great.

Thanks, Robbie

A: 

Hello,

Here is a code snippet that lets you read messages.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.telephony.gsm.SmsManager;
import android.widget.Toast;

public class SMSReceiver extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        Bundle myBundle = intent.getExtras();
        SmsMessage [] messages = null;
        String from= "";
        String body="";
        boolean inSIM=false;

        if (myBundle != null)
        {
            Object [] pdus = (Object[]) myBundle.get("pdus");
            messages = new SmsMessage[pdus.length];

            for (int i = 0; i < messages.length; i++)
            {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                from = ""+messages[i].getOriginatingAddress();
                body = ""+messages[i].getMessageBody();
                inSIM = (messages[i].getIndexOnSim() != -1);
                if (inSIM)
                {
                    int status = messages[i].getStatusOnSim();
                    if (status == SmsManager.STATUS_ON_SIM_UNREAD)
                    {
                       Toast.makeText(context, "Message Unread on SIM: "+from+": "+body, Toast.LENGTH_SHORT).show();
                    }
                }                
            }            
        }
    }
}
Lucas S.
A: 

Hi Lucas S.,

can you help me to find the SMS or MMS outgoing Count app need to know automatically SMS/ MMS will sent when the please ... how can i calculate please help me to find . no need to taken from the LOG need to taken when the SMS will send.

thank you

Dam
+1  A: 

well Please check the link to get the results,

http://youropensource.com/projects/559-get-All-SMS-messages-in-the-Android

FFS it only gets SMS from the phone, not from the SIM at all!
Lo'oris