How to respect network use settings in Android

前端 未结 3 1108
傲寒
傲寒 2020-12-13 16:04

My app performs some backgound data collection and I\'m adding support for the user network preferences, such as performing background updates and data roaming. I have the

3条回答
  •  清歌不尽
    2020-12-13 16:55

    The user may change the settings while your background app is running. The API recommends that you listen to the broadcast message:

    ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED 
    

    Perhaps you are checking cm.getBackgroundDataSetting() prior to sending data, and I suspect this would be sufficient. However, listening to the broadcast message will let you resume sending background data when the settings are changed.

    I believe that either listening to the broadcast message or checking the settings before sending data will suffice. Android docs recommends the former.

提交回复
热议问题