admin管理员组文章数量:1123928
I'm developing an android app using BeeWare. My app need to start an alarm clock when pressed a certain button, which will provide hour and minute parameters. However, the alarm won't be set up.
Here's some relevant code:
def update_time_box(app_self, time_str):
if not app_self.is_calculated_time_added:
## lines of code ##
app_self.cook_button = toga.Button(text="Cocinar", on_press=set_alarm_wrapper(app_self, time_in_seconds))
## some more lines of code ##
def set_alarm(app_self, time_in_seconds):
context = toga.App.app._impl.native
if context is None:
print("El contexto es None")
return
current_time_millis = int(time.time() * 1000)
trigger_time = current_time_millis + (time_in_seconds * 1000)
total_minutes = (trigger_time // (1000 * 60)) % (24 * 60)
alarm_hour_24 = total_minutes // 60
alarm_minute = total_minutes % 60
alarm_intent = Intent(AlarmClock.ACTION_SET_ALARM)
## THESE EXTRAS WON'T WORK ##
alarm_intent.putExtra(AlarmClock.EXTRA_HOUR, alarm_hour_24)
alarm_intent.putExtra(AlarmClock.EXTRA_MINUTES, alarm_minute)
alarm_intent.putExtra(AlarmClock.EXTRA_MESSAGE, "a cocinar!")
## ##
context.startActivity(alarm_intent)
def set_alarm_wrapper(app_self, time_in_seconds):
def wrapped_function(widget):
set_alarm(app_self, time_in_seconds)
return wrapped_function
If i delete those extra parameters, the clock app will show up, but ask the user to set the specifc time and I want to be set up automatically when the button is pressed
I'm developing an android app using BeeWare. My app need to start an alarm clock when pressed a certain button, which will provide hour and minute parameters. However, the alarm won't be set up.
Here's some relevant code:
def update_time_box(app_self, time_str):
if not app_self.is_calculated_time_added:
## lines of code ##
app_self.cook_button = toga.Button(text="Cocinar", on_press=set_alarm_wrapper(app_self, time_in_seconds))
## some more lines of code ##
def set_alarm(app_self, time_in_seconds):
context = toga.App.app._impl.native
if context is None:
print("El contexto es None")
return
current_time_millis = int(time.time() * 1000)
trigger_time = current_time_millis + (time_in_seconds * 1000)
total_minutes = (trigger_time // (1000 * 60)) % (24 * 60)
alarm_hour_24 = total_minutes // 60
alarm_minute = total_minutes % 60
alarm_intent = Intent(AlarmClock.ACTION_SET_ALARM)
## THESE EXTRAS WON'T WORK ##
alarm_intent.putExtra(AlarmClock.EXTRA_HOUR, alarm_hour_24)
alarm_intent.putExtra(AlarmClock.EXTRA_MINUTES, alarm_minute)
alarm_intent.putExtra(AlarmClock.EXTRA_MESSAGE, "a cocinar!")
## ##
context.startActivity(alarm_intent)
def set_alarm_wrapper(app_self, time_in_seconds):
def wrapped_function(widget):
set_alarm(app_self, time_in_seconds)
return wrapped_function
If i delete those extra parameters, the clock app will show up, but ask the user to set the specifc time and I want to be set up automatically when the button is pressed
Share Improve this question asked yesterday AsflumAsflum 112 bronze badges New contributor Asflum is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 0Setting an alarm probably requires a permission, as shown here. You can confirm this is the problem by looking in the app log.
Permissions can be added to your Briefcase configuration as shown here. However, they also need to be requested at runtime. Toga has an API for that, but it isn't publicly documented. For example code, search the Toga repository for request_permissions
.
本文标签: pythonAlarmClock fails when adding 39Extra39 parametersStack Overflow
版权声明:本文标题:python - AlarmClock fails when adding 'Extra' parameters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736608669a1945388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论