Android: 如果错过了备份计划怎么办?

Android: What if backup schedule missed?

我有一个时间表,每天凌晨 3 点进行备份。在此期间,它先进行本地备份,然后再进行云备份到 Google 驱动器。我的问题是:

如果凌晨 3 点互联网不可用,则不会进行云备份。所以如果凌晨 3 点总是没有网络,云备份将永远不会发生。

有什么解决方法吗??

看起来 Completion Events 可以帮助您实施。

Failure - This status indicates that the action associated with this event has permanently failed to be applied to the server. The content or metadata that failed to be applied to the server can be retrieved using the CompletionEvent's getModifiedContentsInputStream or getModifiedMetadataChangeSet, allowing you to try to apply them to the server at a later time.

由于您正在安排上传,您可以通过 EventService 检查 Failures,然后只需执行您的代码即可重试上传根据您选择的时间间隔。

我采取了另一种方法。我在 AndroidManifest.xml 中定义了一个接收器:

<receiver android:name="com.xyz.abc.Receiver"
    android:exported="false"
    android:process=":remote" >
    <intent-filter>
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    </intent-filter>
</receiver>

只要网络连接发生变化,就会触发此事件。然后在 onReceive() 如果需要备份,我开始我的上传过程。这样,我节省了不必要的带宽消耗。

感谢大家的帮助!