0

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

Ganapathy
  • 545
  • 1
  • 6
  • 23
Maani
  • 9
  • 5
  • 2
    So what is the problem you are having? Don't know how to start? – neuhaus Oct 24 '16 at 08: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 Oct 24 '16 at 09:45

3 Answers3

0

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.

neuhaus
  • 3,886
  • 1
  • 10
  • 27
  • I know how to use alarm manager..My question is how i match current time with time stored in mysql db.Because i am using this in reminder type application..And thousands of user will be using the app and they will set reminder. How i will check thousand of rows per second. Thanks for Your response...:p @neuhaus – Maani Oct 24 '16 at 09:55
  • then how i match time in mysql database – Maani Oct 24 '16 at 15:33
  • Read my answer again. – neuhaus Oct 28 '16 at 12:02
0

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

activesince93
  • 1,716
  • 17
  • 37
  • 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 Oct 24 '16 at 09:46
  • No, don't do that, `AlarmManager` does that work for you. – activesince93 Nov 06 '16 at 11:39
  • And if you want to match time, then convert time into milliseconds format, and then compare it like number only, for ex. `if(time1 == time2)` – activesince93 Nov 06 '16 at 11:43
  • Thanks @activesince93...Again my Q is how i match time after each second...After each second it should match current time with time of task stored in mysql.Alarm manager is used in android but how we can do this in php for mysql database.. And please vote my Q up... – Maani Nov 07 '16 at 04:39
  • Then this should be the question of `php`, why did you add `android` tag? – activesince93 Nov 07 '16 at 10:42
0

just use an Alarm Manager and convert unix timestamp to time which is basically multiplying by 1000.

Community
  • 1
  • 1
  • I know how to use alarm manager..My question is how i match current time with time stored in mysql db.Because i am using this in reminder type application..And thousands of user will be using the app and they will set reminder. How i will check thousand of rows per second. Thanks for Your response...:p – Maani Oct 24 '16 at 09:54
  • firebase should be good for this.. I came a across a project where a guy is trying to do something similar.. https://github.com/vinkas0/reminders-android – Manas Dadheech Oct 24 '16 at 10:00
  • Dear that does not fulfill my requirements...Any other idea..? @Manas Dadheech – Maani Oct 24 '16 at 15:31
  • could you be more clear? are you trying to sync say a list of timestamps from your server db with your phone so that you can send automatic smses ?? – Manas Dadheech Oct 25 '16 at 10:50
  • I have a table which have user todo list...it contain userid (Fk) taskName and time..I want to send notiification or reminder alarm to user when time of task reached..I am using mysql db and will send msg or notification through firebase..I actually want code of matching current time with time stored in db... – Maani Oct 25 '16 at 13:07