检查Windows Phone上的“限制后台数据”是否处于活动状态

时间:2014-11-27 09:15:17

标签: c# windows-store-apps windows-phone-8.1 win-universal-app

Data Sense中的设置'限制背景数据'和'限制roamind时的背景数据'。他们阻止后台任务,而不通知应用程序。如何从应用程序检查他们的状态,以便我可以提醒用户?

1 个答案:

答案 0 :(得分:0)

我认为异常消息是检测它的唯一方法。就像在background task sample code中一样。

    // Place the call to Add in a try block in case the user has disabled agents.
    try
    {
        ScheduledActionService.Add( task );
    }
    catch ( InvalidOperationException exception )
    {
        if ( exception.Message.Contains( "BNS Error: The action is disabled" ) )
        {
           // Background agents for this application have been disabled by the user.
        }
        if ( exception.Message.Contains( "BNS Error: The maximum number of ScheduledActions of this type have already been added." ) )
        {

        }
        //...
    }