我正在尝试在我的 Android 应用程序中安排短信。短信正在发送,但它不会被“预定”。这是我的代码。
Intent myIntent = new Intent(ScheduleMessage.this, MyAlarmService.class);
Bundle bundle = new Bundle();
bundle.putCharSequence("Number", Number.getText().toString());
bundle.putCharSequence("Message", Message.getText().toString());
myIntent.putExtras(bundle);
pendingIntent = PendingIntent.getService(ScheduleMessage.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.SECOND,20);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Toast.makeText(getApplicationContext(), "Message: "+Message+" for Number: "+Number, 1).show();
我错过了一些明显的东西吗?没有强制关闭或任何错误。就是这样,短信是立即发送的,而不是在 30 秒后发送(我稍后会考虑按小时、天等安排)。请帮我。我对Android很陌生。