I'm developing an application where I need to send an sms to a particular phone number. Now what I want is the sms should go automatically. The time, at which the message should go automatically, is stored in MySQL database. So I need the code that will keep on checking when that time comes and then send the message to that number automatically. Its a kind of reminder thing. The user will keep a reminder in application
- 2So what is the problem you are having? Don't know how to start?neuhaus– neuhaus2016-10-24 08:17:57 +00:00Commented Oct 24, 2016 at 8:17
- Actually i don't know how i match the time..Should i have a php file that always run and match current time with time specified in db...Thanks for response...Maani– Maani2016-10-24 09:45:53 +00:00Commented Oct 24, 2016 at 9:45
3 Answers
See how to get the number of seconds passed since 1970 for a date value? on how to get the seconds since epoch on android.
To get the same number from MySQL use the UNIX_TIMESTAMP() function.
You can then just compare these two integers.
3 Comments
AlarmManager is the answer. You can set one time alarms as well as repeating alarms.
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future.
Code Example:
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class); intent.putExtra(ONE_TIME, Boolean.TRUE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); // Replace it with the time you get from database long timeYouWantToSetAlarm = System.currentTimeMillis(); am.set(AlarmManager.RTC_WAKEUP, timeYouWantToSetAlarm, pi); Complete tutorial: Android AlarmManager Tutorial
5 Comments
AlarmManager does that work for you.if(time1 == time2)php, why did you add android tag?just use an Alarm Manager and convert unix timestamp to time which is basically multiplying by 1000.