制作一个机器人的Python服务运行在暂停状态 [英] Making an android Python service to run in suspend state

查看:204
本文介绍了制作一个机器人的Python服务运行在暂停状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个使用 Android的脚本我的Python脚本编写的:

Here's my Python script written using android-scripting:

import android, time

droid = android.Android()
interval = 1 # every 1 minute

while True:
    # define your own vibrate pattern here
    droid.vibrate(200)
    time.sleep(0.3)
    droid.vibrate(300)

    time.sleep(60*interval)

它基本上震动每分钟(如动力)。然而,当手机被锁定的屏幕空白了,我没有感觉到任何震动。或许,Android正在冻结脚本(因此while循环)?请注意,我确实运行该脚本作为一种服务(长抽头,然后点击开始作为服务)。

It basically vibrates every minute (like a motivator). However, when the phone is locked with screen blanked out, I don't sense any vibration. Perhaps Android is freezing the script (and hence the while loop)? Note that I am indeed running this script as a service (long-tap and click 'Start as service').

有没有一种方法,使这个脚本所有的工作时间,无论在手机的暂停状态?

Is there a way to make this script work all the time regardless of the phone suspend state?

更新1 :我听到的振动偶尔,不是每分钟..而更像每5-10分钟随机

Update 1: I do hear the vibration occasionally, not every minute .. but rather like every 5-10 minutes randomly.

更新2 :如果我运行该脚本正常(不作为服务),会出现此问题。好像time.sleep不睡了指定的时间。

Update 2: This problems occurs if I run the script normally (not as a service). Seems like "time.sleep" is not sleeping for the specified time.

推荐答案

该脚本环境,绝对是一个二等公民。你想要什么叫做AlarmManager,使用ELAPSED_REALTIME。如果这不是可用于脚本环境,你就完蛋了。

The scripting environment is definitely a second-class citizen. What you want is called the AlarmManager, using ELAPSED_REALTIME. If that's not available for the scripting environment, you're stuck.

脚本环境不是,至少目前,意在完全取代开发工具环境,在那里你可以创建完整的应用程序。它的意思是让你做一些简单的脚本任务,在不能够做更复杂的东西的成本。对不起。

The scripting environment is not, at least currently, intended to be a full replacement for the development kit environment, where you can create full applications. It's meant to allow you to do some simple scripting tasks, at the cost of not being able to do more complicated things. Sorry.

这篇关于制作一个机器人的Python服务运行在暂停状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆