问题
In my android application I have configured a periodic syncing using sync adapter, and its working fine except if the android storage space is running out.If i deleted some files and free up space then sync will start to work.Actually I am just syncing data from my device to the remote server,so there is no need for extra space in device while syncing.So why does the android sync adapter demand some space to work.What I noticed is the sync adapter won't work even if there is a 2% free memory is in the device.Similary I found that the gmail application in android device also won't work if 98 percentage of device memory is used.Gmail will show a couldn't sync message and will not sync and receive any message if device memory is full.So is there any way to start the sync adapter if the memory is full? If not then how can i notify my application users about this fact?
回答1:
This is standard AOSP/Android behaviour.
The SyncManager listens to the Intent.ACTION_DEVICE_STORAGE_LOW intent that is sent when the device is low on storage and cancels any active syncs
It also listens to the Intent.ACTION_DEVICE_STORAGE_OK intent in order to find out that the storage is back to normal and reschedules the syncs
It does this probably because it is backed up by the SyncStorageEngine that stores various information in XML files
Though this answer is late, if you want to notify your users, On Android Oreo and below you can listen to the same broadcasts and notify them. From Android Oreo it gets a bit more tricky as the recommendation is to use the Context.getCacheDir() in order to manage your cache space. Refer to this answer for more details
来源:https://stackoverflow.com/questions/41936001/why-does-the-sync-adapter-wont-work-if-android-storage-space-running-out