Well i was not able to solve the problem of the downloaded code but i wrote this it works and does the same task.
The file is the MainActivity.java in (NameOfYourProgramActivty.Java)
Code:
package com.ahitagni.test2;
import android.app.Activity;
import android.os.Bundle;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.widget.Button;
public class Test2Activity extends Activity {
Button btnSendSMS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sendSMS("5556","Hello this is a test");
}
});
}
private void sendSMS(String phoneNumber,String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber,null,message,null,null);
}
}
And the difference from the code in the book is that the import
Code:
android.telephony.SmsManager;
change that line to
Code:
import android.telephony.gsm.SmsManager;