user1256894
user1256894

Reputation: 13

Implementing code for sending SMS?

I have written code with the intention to send SMS, it work successfully with emulators, but fails on real devices! Can the community help me identify any problems with my code or any relevant information and links to assist me?

public class SmsActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        final Button sendSms = (Button) findViewById (R.id.smsBut);
        sendSms.setOnClickListener(new View.OnClickListener() {         
            public void onClick(View v) {
            // TODO Auto-generated method stub              
            sendSMS("5556", "'hello frinds");
            sendSMS("*********", "'hello frinds");// **= real number
            }
        });

    }// end onCr

    public void sendSMS (String phoneNo, String msg) {      
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, SmsActivity.class), 0);                
        SmsManager sms = SmsManager.getDefault();       
        sms.sendTextMessage(phoneNo, null, msg, null, null);
    }    
}

This is the manifest:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="sms.ecp.ccc"
        android:versionCode="1"
        android:versionName="1.0">
            <uses-sdk android:minSdkVersion="10" />
            <uses-permission android:name="android.permission.SEND_SMS" />
            <application android:icon="@drawable/ic_launcher"android:
                label="@string/app_name" >
            <activity android:name=".SmsActivity" android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>   

Upvotes: 0

Views: 554

Answers (1)

San
San

Reputation: 5697

Change the last line

sms.sendTextMessage(phoneNo, null, msg, pi, null);

Upvotes: 1

Related Questions