I have a widget and want it to open the default clock app when pressed. How can I make this work on all devices? I read something about android.provider.AlarmClock here: AlarmClock | Android Developers but I don't know if this helps in b4a.
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:
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?
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)
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