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]

16 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. Great blog!! I hope you'll post a Data Science blog here.
    data science course in delhi

    ReplyDelete
  6. 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
  7. 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
  8. The information you have posted is important. The objections you have insinuated was worthy. Thankful for sharing.
    training provider in malaysia

    ReplyDelete
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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