Friday, June 27, 2014

ADF Mobile - Get network status dynamically

While working on ADF mobile application with offline/online capabilities, before calling webservices network has to be checked whether it is "connected" or "disconnected".

In my previous article Offline Data Synchronization for ADF Mobile, I was using the javascript to evaluate the network connectivity and store the connection status in pageFlowScope variable. But after subsequent checks pageFlowScope variable was not refreshing properly. Please see the oracle forum for more info,  ADF Mobile - Get network status.

Steps to check network status dynamically:-

1. Java Script to check the network status
 /**
  * Method to check the network status
  */
  application.checkConnection = function () {
     var isConnected;
     var connectionType = navigator.network.connection.type;
     var states = {
      };
     states[Connection.UNKNOWN] = 'Unknown connection';
     states[Connection.ETHERNET] = 'Ethernet connection';
     states[Connection.WIFI] = 'WiFi connection';
     states[Connection.CELL_2G] = 'Cell 2G connection';
     states[Connection.CELL_3G] = 'Cell 3G connection';
     states[Connection.CELL_4G] = 'Cell 4G connection';
     states[Connection.NONE] = 'No network connection';
     if (connectionType == Connection.NONE || connectionType == Connection.UNKNOWN) {
        isConnected = false;
     }else {
        isConnected = true;
     }
     var obj = {connectionType : connectionType, isConnected : isConnected};
     return obj;
  }
2. In managed bean call the application.checkConnection method
public void checkNetworkStatusAction(ActionEvent actionEvent) {
String networkDetails = (String)AdfmfContainerUtilities.invokeContainerJavaScriptFunction(AdfmfJavaUtilities.getFeatureName(),"application.checkConnection",new Object[] { });
   try {
        JSONObject obj = new JSONObject(networkDetails);
        String connectionType = (String)obj.getString("connectionType");
        boolean isConnected = (boolean)obj.getBoolean("isConnected");
        setIsConnected(isConnected);
        setConnectionType(connectionType);
    } catch (JSONException e) {
        throw new AdfException("Error while trying to connect to network", AdfException.ERROR);
    }
}
Application screen looks like below when it deployed to Android device, When there is no network available in the device.


Enable the Mobile Data or Wireless and click on the Check button, Connection Type and Network Status will be displayed on the screen.


You can download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.4.0]

25 comments:

  1. Now available is the mobile app for iPhone. Please visit this link to add the app: ahtcast mobile for iPhone.cell phone tracking app

    ReplyDelete
  2. Deepak,
    In the new Mobile application framework release, you no longer need this Javascript. If you use the EL expression it will dynamicsally refresh when connection status changes.

    Steven Davelaar.

    ReplyDelete
  3. Deepak,

    How to check whether the user is connected to vpn or not?

    ReplyDelete
  4. Hi Deepak,

    I need to find connection type in moblie for which network type they are using. but we are not using ADF mobile.
    We are using ADF and our application is responsive so that we have to check in mobiles.

    Whether this approach is suitable to all (or) only ADF mobile???

    Thanks,
    Venkatesh Danduu

    ReplyDelete
  5. nice blogs
    Get videocon prepaid mobile services to explore the world with easy postpaid bill payment, online prepaid mobile recharge and much more.
    mobile data recharge, internet mobile data

    ReplyDelete
  6. On the off chance that your searching for Online Illinois tag sticker restorations, at that point you have to need to go to the privileged place. data science courses in malaysia

    ReplyDelete
  7. Great blog!! I hope you'll post a Data Science blog here.
    data science course in delhi

    ReplyDelete
  8. I see the best substance on your blog and I unbelievably love getting them.
    HRDF training

    ReplyDelete
  9. I was looking at a portion of your posts on this site and I consider this site is really enlightening! Keep setting up..
    360DigiTMG supply chain analytics beginner's guide

    ReplyDelete
  10. Magnificent Information, I truly refreshing with it, This is fine to peruse and significant star potential, I truly bookmark it, professional expand read. Gratefulness genius sharing. I like it.
    "
    hrdf claimable courses"

    ReplyDelete
  11. You totally coordinate our desire and the assortment of our data.
    HRDF Claimable

    ReplyDelete
  12. The information you have posted is important. The objections you have insinuated was worthy. Thankful for sharing.
    training provider in malaysia

    ReplyDelete
  13. Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!
    business analytics course

    ReplyDelete
  14. It is an obligation of gratitude to share information, continue the great work ... I sincerely enjoy researching your website. great asset ...
    masters in data science

    ReplyDelete
  15. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
    Digital Marketing Training Institutes in Hyderabad

    ReplyDelete
  16. Nice Blog !
    QuickBooks is one such accounting software that is used to handle all the accounting tasks of an organization. In case you find any technical issue in QuickBooks, call us at QuickBooks Technical Support Phone Number 1-(855) 550-7546.

    ReplyDelete
  17. Incredibly conventional blog and articles. I am realy very happy to visit your blog. Directly I am found which I truly need. Thankful to you and keeping it together for your new post.
    data science course gurgaon

    ReplyDelete
  18. Nice & Informative Blog !
    If you keep on seeing QuickBooks Error 2107 on your screen, call us on QuickBooks Support Number to get immediate technical consultation for QuickBooks issues.

    ReplyDelete
  19. What an amazing information you had listed in your blog about digital marketing that clears the doubts about digital marketing. I will also share this blog with my friends. For
    digital marketing institute in aurangabad

    ReplyDelete
  20. Impressive blog post,
    Our Digital Marketing Course with Internship Program consists of 35 Modules. With 1 Hr class everyday from Monday to Friday. You can join the internship along with the course for two months duration.
    Digital Marketing Course with Internship

    ReplyDelete
  21. This post is very simple to read and appreciate without leaving any details out. Great work!
    data scientist course in pune

    ReplyDelete
  22. I see some amazingly important and kept up to length of your strength searching for in your on the site
    data scientist course in malaysia

    ReplyDelete
  23. great article!! sharing these type of articles is the nice one and i hope you will share an article on data science.By giving a institute like 360DigiTMG.it is one the best institute for doing certified courses
    data science training in aurangabad

    ReplyDelete
  24. Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.
    full stack development course

    ReplyDelete