0

I have following code

        <receiver android:name=".SMSListener">
            <intent-filter android:priority="2147483647">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.provider.Telephony.SMS_SENT"/>
            </intent-filter>
        </receiver>




public class SMSListener extends BroadcastReceiver
{
    private SharedPreferences customSharedPreference;

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        customSharedPreference = context.getSharedPreferences("UserSharedPrefs", Activity.MODE_PRIVATE);
        if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
        {
            Bundle bundle = intent.getExtras();           //---get the SMS message passed in---
            SmsMessage[] msgs = null;
            if (bundle != null)
            {
                //---retrieve the SMS message received---
                try{
                    Object[] pdus = (Object[]) bundle.get("pdus");
                    msgs = new SmsMessage[pdus.length];
                    for(int i=0; i<msgs.length; i++)
                    {
                        msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                    }

                    Editor editor = customSharedPreference.edit();
                    editor.putString("lastSmsReceived", String.valueOf(System.currentTimeMillis()));
                    editor.commit();

                }catch(Exception e){
//                            Log.d("Exception caught",e.getMessage());
                }
            }            
        }
        else  if(intent.getAction().equals("android.provider.Telephony.SMS_SENT"))
        {
            Editor editor = customSharedPreference.edit();
            editor.putString("lastSmsSent", String.valueOf(System.currentTimeMillis()));
            editor.commit();
            Log.d("SMS Sent", "SMS Sent");
        }
    }
}

With permissions

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

It detects SMS READ But SMS Sent is not detected. What else am I missing

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

3

There is no such action android.provider.Telephony.SMS_SENT. Android does not broadcast sent messages.

There is an alternative solution described here: Android Broadcast Receiver for Sent SMS messages?

Community
  • 1
  • 1
kupsef
  • 3,357
  • 1
  • 21
  • 31