Android Question Simple alarm clock

Sergey_New

Well-Known Member
Licensed User
Longtime User
Please help me create an alarm clock that goes off once a day at a set time, for example at 9:00. When triggered, a notification should appear. API 29+. I did not find any suitable examples.
Maybe I asked the question incorrectly, but in other words, I do not need an alarm clock, but I need the application to notify at the right time about the time that has come.
This is what I have come to. Now I need the notification to come not when I press a button, but when the required time is reached.
 

Attachments

  • NB6_B4A.zip
    13.2 KB · Views: 9
Last edited:

Alex_197

Well-Known Member
Licensed User
Longtime User
Please help me create an alarm clock that goes off once a day at a set time, for example at 9:00. When triggered, a notification should appear. API 29+. I did not find any suitable examples.
Maybe I asked the question incorrectly, but in other words, I do not need an alarm clock, but I need the application to notify at the right time about the time that has come.
This is what I have come to. Now I need the notification to come not when I press a button, but when the required time is reached.
check this https://www.b4x.com/android/forum/threads/setting-alarm-for-a-specific-time.71167/
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
check this
Where should I place this code in my example?
B4X:
Dim i As Intent
   i.Initialize("android.intent.action.SET_ALARM", "")
   i.PutExtra("android.intent.extra.alarm.HOUR", 16)
   i.PutExtra("android.intent.extra.alarm.MINUTES", 58)
   i.PutExtra("android.intent.extra.alarm.SKIP_UI", False)
  StartActivity(i)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Where should I place this code in my example?
B4X:
Dim i As Intent
   i.Initialize("android.intent.action.SET_ALARM", "")
   i.PutExtra("android.intent.extra.alarm.HOUR", 16)
   i.PutExtra("android.intent.extra.alarm.MINUTES", 58)
   i.PutExtra("android.intent.extra.alarm.SKIP_UI", False)
  StartActivity(i)
I think that you can use some button like Set the Alarm and put it on button click.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
i.PutExtra("android.intent.extra.alarm.EXTRA_DAYS, Array(0,1,2,3,4,5,6).....something like this. Read up about it and see how to pass the array. The numbers (int) is the days of the week.

B4X:
import android.content.Intent;
import android.provider.AlarmClock;
import java.util.ArrayList;
import java.util.Calendar;

// ...

Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, 7); // Set alarm for 7 AM
alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, 30); // Set alarm for 7:30 AM
alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, "Wake up!");

ArrayList<Integer> alarmDays = new ArrayList<>();
alarmDays.add(Calendar.MONDAY);
alarmDays.add(Calendar.WEDNESDAY);
alarmDays.add(Calendar.FRIDAY);

alarmIntent.putExtra(AlarmClock.EXTRA_DAYS, alarmDays); // Set alarm to repeat on Mon, Wed, Fri
alarmIntent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
alarmIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, false); // Do not skip the UI to confirm the alarm

startActivity(alarmIntent);
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
The numbers (int) is the days of the week.
Thank you!
I need to receive a notification at the right time on any day and month. Maybe the code can be simplified? And if it's not too much trouble, please correct my example.
 
Upvote 0
Top