简体   繁体   中英

Simple http request on WP8 on obscured

So basically I made it so my app runs in the background if the phone is locked using this

PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;

Then I created an event so when the application is obscured(the phone is locked) it would run doing the following.

PhoneApplicationFrame phoneAppRootFrame = RootFrame;
App.RootFrame.Obscured += RootFrame_Obscured;

Now here is my request code.. there has to be something wrong with it, though I'm not sure what anymore. I've been trying so many different ways of just doing a simple get request, I don't even need to parse any response. It just never seems to work, anyways here it is:

private void RootFrame_Obscured(object sender, ObscuredEventArgs e)
{
  string url = "http://localhost:8080/someserver/javaQuery?request=storeId&id=someId";
  HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.CreateHttp(url);
  webRequest.BeginGetResponse(new AsyncCallback(httpComplete), webRequest);
}

private static void httpComplete(IAsyncResult asyncResult){

}

I'm completely positive that the RootFrame_Obscured function is running, but the request code itself is probably wrong. Any insight would be helpful, thanks.

You are not allowed to perform network calls under the lock screen.

Checklist for apps that disable app idle detection

If your Windows Phone app disables app idle detection to run under the lock screen, you should perform the following tasks to reduce your app's power consumption while the lock screen is engaged.

  • Signal your app that new network requests and isolated storage operations shouldn't be performed.

If you need to track this event you can do that in Unobscured event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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