简体   繁体   English

与服务器通信-Android应用

[英]Communicating with Server - Android App

I have an android application which is uploading and downloading a file in every 15 min. 我有一个android应用程序,它每15分钟上传和下载一个文件。 I am using AlarmManager setRepeating() to do this, but it is consuming lot of Battery and Inefficient. 我正在使用AlarmManager setRepeating()来执行此操作,但是它消耗了大量的电池并且效率低下。 But i want to restructure this app so that it will work on Marshmallow and above devices. 但我想重组此应用程序,以便它可以在棉花糖及以上设备上使用。 I read about JobScheduler and sync adapter , but the challenge is Doze mode . 我读到有关JobScheduler同步适配器的信息 ,但是挑战是打ze模式 As per Official Documentation 根据官方文件

https://developer.android.com/training/monitoring-device-state/doze-standby.html#understand_app_standby https://developer.android.com/training/monitoring-device-state/doze-standby.html#understand_app_standby

JobScheduler and Sync Adapter wont work on Doze mode. JobScheduler和同步适配器在打on模式下无法使用。

So, How to make android app and server communication for every 15 min, even in doze mode. 因此,即使在打ze模式下,如何每15分钟进行一次android应用和服务器通信。

Thanks. 谢谢。

As per Android developer documents AlarmManager will continue work on marshmallow and above 根据Android开发人员文档, AlarmManager将继续在蛋白软糖及更高版本上工作

Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window. 标准AlarmManager警报(包括setExact()和setWindow())将推迟到下一个维护窗口。

  1. If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle() . 如果您需要设置在Doze中触发的警报,请使用setAndAllowWhileIdle()setExactAndAllowWhileIdle()
  2. Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire. 使用setAlarmClock() 设置的警报继续正常触发-在这些警报触发之前,系统立即退出Doze。

Use Alarmmanager and let your users deactivate Doze mode for your app (Whitelisting). 使用Alarmmanager,让您的用户为您的应用程序禁用“打ze”模式(白名单)。

Alarmmanager do not consuming a lot of Battery. Alarmmanager不会消耗大量电池。 Alarm event comes from operating system. 警报事件来自操作系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM