Today we are going to see how to detect the mobile device is connected to internet or not in Sencha Touch 2. We are going to use Ext.device.Connection class that contains isOnline() method, which is used to check if the current device is currently online or not. This method will return true, if you are currently online otherwise return false.
Let's see the implementation
Here is the output, when i run the above code in google chrome with internet connection
Here is the output, when i run the above code in google chrome without internet connection
Important Note:
You need to add the Ext.device.Connection class as the requires in the Ext.Application class, otherwise you will get connection is undefined error.
Hope, you enjoyed this Post.
Let's see the implementation
if (Ext.device.Connection.isOnline()) { Ext.Msg.alert("I am online"); } else { Ext.Msg.alert("I am offline"); }
Here is the output, when i run the above code in google chrome with internet connection
Here is the output, when i run the above code in google chrome without internet connection
Important Note:
You need to add the Ext.device.Connection class as the requires in the Ext.Application class, otherwise you will get connection is undefined error.
Hope, you enjoyed this Post.
Hi,
ReplyDeleteHow do you define Ext.device.Connection in Ext.Application?
I tried:
Ext.application({
appFolder: 'XXX',
name: 'XXX',
requires: 'Ext.device.Connection',
});
But it can't find Connection.js
Any help would be greatly appreciated.
I think Sencha Touch can't able to load SDK files. Please make sure, SDK path is set correctly.
DeleteThanks and Regards,
Suresh Ariya
Please add Conection.js file on App.js's requires array
ReplyDeletethis is not working in android build...
ReplyDeletei gave permission int androidmanifest.xml , but its invain