Opening default clock/alarm app

Erel

Administrator
Staff member
Licensed User
You can set an alarm with this code:
B4X:
Sub SetAlarm(Hour As Int, Minutes As Int)
   Dim i As Intent
   i.Initialize("android.intent.action.SET_ALARM", "")
   i.PutExtra("android.intent.extra.alarm.HOUR", Hour)
   i.PutExtra("android.intent.extra.alarm.MINUTES", Minutes)
   i.PutExtra("android.intent.extra.alarm.SKIP_UI", False)
   StartActivity(i)
End Sub
You will also need to add this line to the manifest editor:
B4X:
AddPermission(com.android.alarm.permission.SET_ALARM)
It will open the alarm manager with the time set.
 

mkvidyashankar

Active Member
Licensed User
way to read the alarm settings

This code is working fine, i am trying to read the alarm date and time to show in my app. but not found any clues.

Could you please guide me.
 

mkvidyashankar

Active Member
Licensed User
Thanks Erel. It work.
I set the alarm successfully
But how to cancel the alarm from the app?
can we access the alarm setting screen from the app?
 

mkvidyashankar

Active Member
Licensed User
This method is working fine
But in kindle fire HD it throws error
No activity found to handle intent.
I.e set_alarm


How to. Fix thi
 

AaronF88

Member
Licensed User
Thanks for the help with setting the alarm. Everything is going well except two things, forgive me if these are basic questions as I'm new to this

1) Phone.GetSettings("next_alarm_formatted") takes the next set alarm in the android default clock app. Is there any way of changing it to pick up the time from another app, say Timely?

2) With regards to cancelling alarms I don't quite understand what you meant by "Try to call the intent in the second post without the time parameters." I have tried to pass the intent without adding android.intent.extra.alarm.HOUR etc and it does not seem to cancel an upcoming alarm but bring up the clock app with the alarm picker. Am I doing something wrong here?

http://pastebin.com/RzpmEwre
 

M. Giray Ozkan

Member
Licensed User
Dear @Erel

How can I pass "android.intent.extra.alarm.DAYS" to this intent? I've tried the following code with no luck.

B4X:
    Dim days As List
    days.initialize
    days.Add(1)
    days.Add(2)
    days.Add(3)


      Dim i As Intent
      i.Initialize("android.intent.action.SET_ALARM", "")
      i.PutExtra("android.intent.extra.alarm.DAYS", days)
      i.PutExtra("android.intent.extra.alarm.HOUR", 20)
      i.PutExtra("android.intent.extra.alarm.MINUTES", 35)
      i.PutExtra("android.intent.extra.alarm.MESSAGE","Some Message")
      i.PutExtra("android.intent.extra.alarm.SKIP_UI", False)
      StartActivity(i)
 

aeropic

Active Member
Licensed User
2. The API doesn't provide any way to cancel alarms. You can use this action to show the list of alarms: android.intent.action.SHOW_ALARMS
Hi Erel, I wonder if the AlarmManager would be a solution to cancel a pending alarm
http://developer.android.com/reference/android/app/AlarmManager.html

there is cancel method that could be used if the pending intent is known
cancel(PendingIntent operation)

But i don't know how to call it from B4A :(
B4X:
Sub cancel_alarm() '<-------------- pass the intent ?
   Dim r As Reflector
   
   r.Target = r.GetContext
  r.Target = r.RunMethod2("getSystemService", "alarm", "java.lang.String")
  r.RunMethod("cancel")  '<-------------  pass the intent ?
  Log("cancel (PendingIntent operation)") '<--------------
End Sub
regards
Alain
 
Last edited:
Top