Pop_up_2.class
Intent i = new Intent(Pop_up_2.this, Smscreator.class);
PendingIntent pIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager aManager = (AlarmManager) getSystemService(ALARM_SERVICE);
c.set(Calendar.HOUR_OF_DAY,mHour);
c.set(Calendar.MINUTE,mMinute);
c.set(Calendar.SECOND,00);
c.set(Calendar.YEAR,y);
c.set(Calendar.MONTH,m);
c.set(Calendar.DAY_OF_MONTH,d);
aManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pIntent);
Toast.makeText(getApplicationContext(), "Sms scheduled: " + message, Toast.LENGTH_SHORT).show();
sendBroadcast(i);
Smscreator.class
public class Smscreator extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(no, null, message, null, null);
Toast.makeText(context, "SMS sent.",
Toast.LENGTH_LONG).show();
}
}
I have been trying to send the SMS at the user specified date and time, but the SMS gets sent immediately. I have been trying to find out the error for a long time, but I can't find any. Both my activity and my broadcast receiver have been declared in AndroidManifest. Someone please give me a proper answer on how I can achieve this.
I implemented for notification schedule on given time. Just take this code as reference: