通过命令强制执行JobService

81 篇文章 3 订阅
9 篇文章 0 订阅

    android开发中经常用JobService来做定时操作,但是这个定时任务又收到系统影响,系统为了耗电和网络等因素会将JobService的触发时间做一下优化。

    但是这就苦了android开发者,写了一个JobService想看一下效果往往等半天也等不来一次触发,给代码调试带来很大困难。研究了好久,才发现adb里有命令可以强制触发JobService。

命令如下:

run [-f | --force] [-u | --user USER_ID] PACKAGE JOB_ID

例如包名是 com.test.pkg  ,JobID是 1000

命令就是 :

adb shell cmd jobscheduler run -f com.test.pkg 1000

完整help如下:

xc@xc-OptiPlex-7040:~/sagit-o$ adb shell cmd jobscheduler
Job scheduler (jobscheduler) commands:
  help
    Print this help text.
  run [-f | --force] [-u | --user USER_ID] PACKAGE JOB_ID
    Trigger immediate execution of a specific scheduled job.
    Options:
      -f or --force: run the job even if technical constraints such as
         connectivity are not currently met
      -u or --user: specify which user's job is to be run; the default is
         the primary or system user
  timeout [-u | --user USER_ID] [PACKAGE] [JOB_ID]
    Trigger immediate timeout of currently executing jobs, as if their.
    execution timeout had expired.
    Options:
      -u or --user: specify which user's job is to be run; the default is
         all users
  monitor-battery [on|off]
    Control monitoring of all battery changes.  Off by default.  Turning
    on makes get-battery-seq useful.
  get-battery-seq
    Return the last battery update sequence number that was received.
  get-battery-charging
    Return whether the battery is currently considered to be charging.
  get-battery-not-low
    Return whether the battery is currently considered to not be low.
  get-storage-seq
    Return the last storage update sequence number that was received.
  get-storage-not-low
    Return whether storage is currently considered to not be low.
  get-job-state [-u | --user USER_ID] PACKAGE JOB_ID
    Return the current state of a job, may be any combination of:
      pending: currently on the pending list, waiting to be active
      active: job is actively running
      user-stopped: job can't run because its user is stopped
      backing-up: job can't run because app is currently backing up its data
      no-component: job can't run because its component is not available
      ready: job is ready to run (all constraints satisfied or bypassed)
      waiting: if nothing else above is printed, job not ready to run
    Options:
      -u or --user: specify which user's job is to be run; the default is
         the primary or system user

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值