Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User vinayppatil's Avatar
    Join Date
    Dec 2012
    Posts
    51
    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 Loukt's Avatar
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    177
    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
    Registered User vinayppatil's Avatar
    Join Date
    Dec 2012
    Posts
    51
    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
    Registered User vinayppatil's Avatar
    Join Date
    Dec 2012
    Posts
    51
    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 Loukt's Avatar
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    177
    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
    Registered User vinayppatil's Avatar
    Join Date
    Dec 2012
    Posts
    51
    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.

  7. #7
    Nokia Developer Champion Loukt's Avatar
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    177
    Glad that the work around works for you.

    Good luck

  8. #8
    Registered User vinayppatil's Avatar
    Join Date
    Dec 2012
    Posts
    51
    I came through a really nice implementation for network detection. Network detector

    So all i did was included NetworkDetector class in my app. Created an instance of NetworkDetector in app.xaml and added a OnNetworkON handler on it.

    NetworkDetector nd = NetworkDetector.Instance;

    nd.OnNetworkON += new EventHandler<NetworkAvailableEventArgs>(nd_OnNetworkON);

    nd.SetNetworkPolling(minutes,seconds,milliseconds);

    ======

    void nd_OnNetworkON(object sender, NetworkAvailableEventArgs e)
    {
    //Your implementation when network is available.
    }

    Thanks and regards

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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved