Correct way to send SMS messages through Android

1.1k views Asked by At

Hello Stack Overflow Community,

So I have searched all over the net for a solution to this, but cannot find someone with a similar problem...

I am writing a small program that receives texts and responds to them. The receiving portion works fine, but I have yet to send a successful text. The small test program below has produced the same results. Below is the method that I used to try and send along with a snippet of the logcat. The sendTextMessage method has produced absolutely nothing. I have been testing this over my LG Ally not the emulator. I just thought I would ask if there is something I'm missing before I decide it is just the phone.

Notes... The permissions are set correctly. Obviously the "xxxxxxxxxx" represents an actual number.

Thanks in advance,

Jason

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;

public class test extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.w("MARK", "APPLICATION START");
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage("xxxxxxxxxx", null, "AUTO RESPONSE", null, null);
        Log.w("MARK", "sendTextMessage CALLED");
    }
}

02-27 12:42:02.471: WARN/MARK(9903): APPLICATION START
02-27 12:42:02.471: WARN/MARK(9903): sendTextMessage CALLED
02-27 12:42:02.591: INFO/ActivityManager(1372): Displayed activity com.test/.test: 135 ms (total 135 ms)
1

There are 1 answers

1
Asahi On

Starting activity using sms intent will invoke an editor and wait for user to press Send button. To do it programatically, try using SmsManager