×

Discussion Board

Results 1 to 8 of 8

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Getting network change notification on windows phone

    I am currently stuck with my application over getting network change notification. I have a scenario in my app where in if user has no internet connectivity, commands needs to be sent to the server keeps on getting queued and once network is available all the queued commands are sent to the server. Now i want to be notified by the system when network is available.

    What i tried.?
    Following this post i registered a network changed listener but it works only when user is on that particular screen where i have added the listener. I have lot of screens in my app. Do i need to add network change listener on all the screens. Isn't there a way to just write logic at one place and get notified about network change on all the screens.

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    295

    Re: Getting network change notification on windows phone

    If you are using the MVVM pattern in your app, registered the event in the View-Model.
    Otherwise try to register the event in App.xaml.cs (I didn't try it yet)

    Where are your queued commands being saved ?

  3. #3
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Getting network change notification on windows phone

    Hi Loukt, thanks for your response.

    Quote Originally Posted by Loukt View Post
    If you are using the MVVM pattern in your app, registered the event in the View-Model.
    Yes i have followed MVVM design pattern. But almost every view has its own ViewModel so this solution wont do.

    Quote Originally Posted by Loukt View Post
    Otherwise try to register the event in App.xaml.cs (I didn't try it yet)
    Haven't tried with this yet. Will try it today and get back.

    Quote Originally Posted by Loukt View Post
    Where are your queued commands being saved ?
    The commands are stored in isolated storage.

  4. #4
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Getting network change notification on windows phone

    I just figuered out
    NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(OnNetworkChange);
    does not fires for network lost and network gain events.
    I was conneted to a wifi netowk(mobile network was off) then i went to a place where i had no wifi in range i.e i was disconnected from the wifi but the NetworkChange event didin't fired. Then i again walked into wifi range, i get the network back but still NetworkChange didn't fired up. Is this happening because my IP is not changing. If yes then how do i get Notifications for network connected/ disconneted events on same IP.?

  5. #5
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    295

    Re: Getting network change notification on windows phone

    Yes OnNetworkChange will only fire up when you IP address change so If your on a wifi you get an IP adress (192.168.x.x) but that doesn't mean you have an Internet Connection.
    Regarding the Wifi Range it should fireup since out of the wifi range you lose the ip adress once back you get it back.
    You can put a DispatcherTimer that will try every 15 30sec or xx time to connect to the server and add a PeriodicAgent which will try send those commands to the server when internetconnection is available even if the application is closed.
    Or just notify the user that there is no internet connection (the notification can be a simple warning marker in the top right corner and when clicked it it will retry connect to the server.)

  6. #6
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Getting network change notification on windows phone

    Quote Originally Posted by Loukt View Post
    Regarding the Wifi Range it should fireup since out of the wifi range you lose the ip adress once back you get it back.
    I tried it with another device. Sadly doesn't works.
    Quote Originally Posted by Loukt View Post
    You can put a DispatcherTimer that will try every 15 30sec or xx time to connect to the server and add a PeriodicAgent which will try send those commands to the server when internetconnection is available even if the application is closed.
    Or just notify the user that there is no internet connection (the notification can be a simple warning marker in the top right corner and when clicked it it will retry connect to the server.)
    I used DispatcherTimer and it works seamless. hope it wont cause any blocks in the UI. But using a PeriodicAgent seems typical. ResourceIntensiveTask is completely out of question in my case because of its need to have device pugged in to external power source.
    Even there are lot of constraints on PeriodicTask like 25 seconds execution time, battery saver mode etc. Will see what i can come up with.
    Anyways thanks for the help Loukt.

Similar Threads

  1. Change volume in windows phone 8
    By kogany in forum Windows Phone General
    Replies: 2
    Last Post: 2012-12-14, 00:31
  2. Replies: 1
    Last Post: 2012-08-14, 10:49
  3. Notification on change in IAP
    By vittalx in forum Open C/C++
    Replies: 1
    Last Post: 2009-07-27, 13:04
  4. Get Notification Change
    By MariaManrique in forum Symbian Networking & Messaging (Closed)
    Replies: 18
    Last Post: 2007-11-14, 20:22
  5. Replies: 1
    Last Post: 2002-07-16, 06:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×