Android - Run a python method from AlarmManager while kivy app is paused

769 views
Skip to first unread message

Ian Alexander

unread,
Dec 10, 2014, 2:46:57 PM12/10/14
to kivy-...@googlegroups.com
Hello everyone,

I've just started delving into working with the android api from kivy so hopefully this all makes sense!
The code below schedules an event with AlarmManager which fires every 20 seconds


System = autoclass ('java.lang.System')
Context = autoclass('android.content.Context') 
Intent = autoclass('android.content.Intent')  
PendingIntent = autoclass('android.app.PendingIntent')  
Calendar = autoclass('java.util.Calendar') 
AlarmManager = autoclass('android.app.AlarmManager')  
activity = autoclass('org.renpy.android.PythonActivity').mActivity
PENDING_INTENT_REQUEST_CODE = 889754

calendar = Calendar.getInstance()
calendar.setTimeInMillis(System.currentTimeMillis())
calendar.add(Calendar.SECOND, 20)
alarm = activity.getSystemService(Context.ALARM_SERVICE)

intent = Intent(self.alarm_callback)
                   
pending_intent = PendingIntent.getBroadcast(activity, 0, intent, 0)
alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 20, pending_intent)



My question is how to call python methods directly with the Intent?
I've tried following the code here, but haven't been able to work it out how it was done:

Also, will the python method still run if the app is in a paused state?

Thanks!

p.s.
It's possible to use intent = Intent(Intent.ACTION_PROVIDER_CHANGED), and capture that with the BroadcastReceiver from android.broadcast (which can run the python method), but that seems quite a round about method
Reply all
Reply to author
Forward
0 new messages