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.
Add a comment  | 

1 Answer 1

Reset to default 0

Setting 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