- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在尝试制作一个适用于 Android 打瞌睡功能的应用程序,但我遇到的问题是,当手机 (Android 6) 最近锁定屏幕并且我使用 Android Studio 运行该应用程序时,作业永远不会执行。阅读文档并看到这个 Doze 图后: 我希望有一个时间窗口来发出 HTTP 请求来更新我的应用程序,但我已经等待了至少 15 分钟,但从未发生过。
正在创建作业并在 onCreate 方法中安排,如下所示:
ComponentName componentName =
new ComponentName(getApplicationContext(), ConnectJobService.class);
jobInfo = new JobInfo.Builder(33, componentName)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build();
int resultCode = jobScheduler.schedule(jobInfo); //resultCode == JobScheduler.RESULT_SUCCESS > true
这是我的 list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xg.frequencytester">
<application
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".ConnectJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
/>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
最佳答案
在 Android 6 上,关闭屏幕后不会进入打盹模式,而是 after an unspecified amount of time .
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode.
因此,我怀疑这不是问题所在。一种可能的选择是 JobScheduler
受到 CPU 在屏幕关闭几秒钟后进入低功耗模式的影响。 (相关:Keeping the Device Awake)
根据我的经验,即使在设备解锁且屏幕打开的情况下安排任务也可能会延迟几秒钟,因此您遇到的情况可能与此类似。
我会尝试使用退避期和截止日期。请注意,默认退避策略是指数:
ComponentName componentName =
new ComponentName(getApplicationContext(), ConnectJobService.class);
jobInfo = new JobInfo.Builder(33, componentName)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setOverrideDeadline(5000L)
.setBackoffCriteria(500L, JobInfo.BACKOFF_POLICY_LINEAR)
.build();
int resultCode = jobScheduler.schedule(jobInfo); //resultCode == JobScheduler.RESULT_SUCCESS > true
注意 default initial backoff是 30000ms 和 maximum是 18000000 毫秒(这是 5 小时!)。
关于java - 在锁定屏幕的情况下运行应用程序时,JobScheduler 作业无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835155/
我知道 Android native (后 Lollipop)JobScheduler 和 GCM JobScheduler 都可以在重启后保留作业,但应用更新后呢?应用更新后我是否仍会调用作业? 谢
如何模仿 Android JobScheduler (或 GcmNetworkManager )Android 上 RxJava 的行为? 具体来说,我想要这个功能 了解网络 Activity 自动退
我有一个 jobscheduler,它发送由启动警报触发并被结束警报取消的通知,我有一个问题,如果我从最近的应用程序中删除应用程序或我重新启动手机,警报会在指定时间触发吗?以及作业调度程序会发生什么
注意:这不是重复的,请阅读问题 我想在设备每次充电和 WIFI 时运行一个作业。每次满足这些条件时,该作业最多必须运行一次。这意味着如果我让手机在 wifi 开启的情况下充电一夜,工作就不会重复。只有
我想每天调用一个方法来在我的应用程序中生成僵尸。 以下方法应创建执行此操作的 JobScheduler。 我的问题是:我是只调用一次这个方法,还是可以在应用程序启动时每次都调用它? public st
我正在使用 JobScheduler.setPeriodic() 来重复我的 JobIntentService。它第一次工作但从不重复。运行于安卓7.0 并发检查.java int mdelaymil
这可能吗?我需要启动我的前台服务,因为我在 UI 线程中使用它, 示例:每 25 分钟在我的应用中播放一个视频,该视频已关闭。 最佳答案 我认为这不是使用 JobScheduler 的最佳用例,但您可
我检查了从 Android API 级别 21 开始可以使用的 JobScheduler API。我想安排一个需要互联网并且每天只运行一次或可选的每周运行一次的任务(如果成功执行)。我没有找到关于这种
在 Android 模拟器上运行时,我无法让 JobScheduler 启动计划作业。如果我在运行 Android 6.0.1 的真实Samsung Galaxy S7 和 Nexus 5X 上进行测
我想在每天的特定时间启动 JobScheduler,并在 3 小时后完成。 我每 20 分钟触发一次作业,持续 3 小时,但在 JobInfo.Builder 类中没有在准确时间启 Action 业的
我的应用使用这种经典模式来安排周期性任务: 通过 AlarmManager 设置准确的闹钟(通过 setExactAndAllowWhileIdle(),因为即使在打瞌睡时它也必须关闭) 通过 Wak
这是我设置工作的方式: val builder = JobInfo.Builder(1, ComponentName(this, PullDataJob::class.java))
如何重新安排我使用 setPeriodic() 启动的 JobScheduler,我想稍后通过用户输入更改调度程序时间。 JobInfo.Builder builder = new JobIn
JobInfo.Builder 中的方法“setRequireDeviceIdle”到底是如何工作的?根据我在 Android 文档 (https://developer.android.com/re
我们正在通过 JobScheduler 实现作业用于后台加载数据。这项工作每天大约会触发一次。我们可以使用哪些工具来测试此功能(可能是 ADB)? 用例能够模拟作业运行所需的条件,或者只是明确地说“运
我正在试用 Android Lollipop 附带的新 JoScheduler API。到目前为止,我已经成功地创建并运行了一个延迟为 6000 毫秒的作业,没有任何网络要求。 但是,我刚刚尝试通过使
STEP_COUNTER 传感器的 Android 文档有点困惑。 根据这个:Android Sensor doc我应该始终注册 STEP_COUNTER 传感器,否则计步器传感器根本不会计数。这一切
我正在学习如何在 Android 中结合使用 JobSchedule 和 AsyncTasks。按照一些指南,我有以下 JobService 实现: @RequiresApi(Build.VERSIO
jobscheduler 每 10 分钟定期运行一次。一旦应用程序运行并保持每 10 分钟定期运行一次,我必须做些什么才能运行计划。现在发生的情况是:安装应用程序后,运行计划需要 10 分钟。如何让它
我遵循了一些关于 android 中的作业调度的在线教程,我尝试这样做,发现下面的代码编译没有错误。但问题是 onPostExecute/doInBackground 返回消息中没有 toast。有什
我是一名优秀的程序员,十分优秀!