[Java for Android App Development] Sandy||Striker:
i am trying to send Message at a scheduled time in my app

here is my activty

case R.id.bSubmitborrowitem:

String b = mDateDisplay.getText().toString();
String c = mTimeDisplay.getText().toString();
String a = b + "-" + c;
String d = tv1.getText().toString();
String e = "hello";
Toast.makeText(getApplicationContext(), a,
Toast.LENGTH_LONG).show();

//*************coding of sms start here***********************//

// TODO Auto-generated method stub

String pick_no;
pick_no=d;
if(d.length()!=0&& e.length()!=0)
{

Intent b_Intent=new Intent();
b_Intent.setAction(MyAlarmService.ACTION);
b_Intent.putExtra("RQS", MyAlarmService.RQS_STOP_SERVICE);

Intent myIntent=new Intent(this,MyAlarmService.class);
myIntent.setAction(Intent.ACTION_SEND);
Bundle bundle=new Bundle();
bundle.putString("sms_number", d);
bundle.putCharSequence("body", e);
bundle.putString("contact_choose", d);
myIntent.putExtras(bundle);

pi=PendingIntent.getService(this, 0, myIntent,1);
pn.add(PendingIntent.getBroadcast(this, 0, b_Intent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK));
pn.add(pi);
AlarmManager alarm_manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, mDay);
calendar.set(Calendar.MONTH, mMonth);
calendar.set(Calendar.YEAR, mYear);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, mminute);
calendar.clear();
alarm_manager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pi);

Toast.makeText(this, "your msg will be sending at "+hour+" hours and "+mminute+" min", Toast.LENGTH_LONG).show();

//*************coding of sms start here***********************//

And here is Service class

public class MyAlarmService extends Service {

String To,message_body,pick;
NotifyServiceReceiver notifyServiceReceiver;

final static String ACTION = "NotifyServiceAction";
final static String STOP_SERVICE = "";
final static int RQS_STOP_SERVICE = 1;

private static final int MY_NOTIFICATION_ID=1;
private NotificationManager notificationManager;
private Notification myNotification;

SmsManager sms;
[MENTION=439709]override[/MENTION]
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}

[MENTION=439709]override[/MENTION]
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(this, "Service created", Toast.LENGTH_LONG).show();
notifyServiceReceiver = new NotifyServiceReceiver();
}

[MENTION=439709]override[/MENTION]
public void onDestroy() {
// TODO Auto-generated method
super.onDestroy();
Toast.makeText(getBaseContext(), "destroy",
Toast.LENGTH_SHORT).show();

}

private void CancelService() {
// TODO Auto-generated method stub

}

[MENTION=439709]override[/MENTION]
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION);
registerReceiver(notifyServiceReceiver, intentFilter);

Bundle bundle=intent.getExtras();
Toast.makeText(this, "service Started", Toast.LENGTH_LONG).show();

String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);

//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
[MENTION=439709]override[/MENTION]
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();

break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));

registerReceiver(new BroadcastReceiver(){
[MENTION=439709]override[/MENTION]
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
sms = SmsManager.getDefault();
sms.sendTextMessage(bundle.getString("sms_number"), null,(String) bundle.getCharSequence("body") , sentPI, deliveredPI);

notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_launcher, "Notification!",System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "Message Notification";
PendingIntent myIntent1 = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, People.CONTENT_URI), 0);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context,notificationTitle,notificationText, myIntent1);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
Toast.makeText(this, "your msg will be sending at ", Toast.LENGTH_LONG).show();
return START_STICKY;
}

[MENTION=439709]override[/MENTION]
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
return super.onUnbind(intent);
}

public class NotifyServiceReceiver extends BroadcastReceiver{

[MENTION=439709]override[/MENTION]
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
int rqs = arg1.getIntExtra("RQS", 0);
if (rqs == RQS_STOP_SERVICE){
stopSelf();
}
}

}
}

everything is fine.. there is no error in code. even the toast come up when i press the submit button..

but it is not sending message .. plzz help

Edit1 app is sending sms now but not on schedule time . it is sending sms instantly