Thursday, January 29, 2015

Introducing to PhoneGap Events

Here is a small list of current available events implemented from current PhoneGap version.
Thery aren't supported for all(100%) PhoneGap supported platforms.
See every link target for ensure the current support for your s.o. application target.

A small example to test some of these states:
(to insert in the head tag of your test page).

<script type="text/javascript" src="cordova.js" />
<script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load              
    function onDeviceReady () {
        alert ("device ready!!!") ;
    }
    function onOnline () {
        alert ("online!!!") ;
    }
    function onOffline () {
        alert ("offline!!!") ;
    }
      
    document.addEventListener("deviceready", onDeviceReady, false);
    document.addEventListener("online", onOnline, false);
    document.addEventListener("offline", onOffline, false);        

</script>


For battery events you need to install, before, a battery-status plugin.
From shell, within $application_project_home_folder, give this command:

phonegap plugin add org.apache.cordova.battery-status

At last check into AndroidManifest.xml for

<uses-permission android:name="android.permission.BROADCAST_STICKY" />

and into config.xml for iOS

<plugin name="Battery" value="CDVBattery" /> 

For other platforms see here

For online/offline status you need to install, before,
From shell, within $application_project_home_folder, give this command:

phonegap plugin add org.apache.cordova.network-information

At last check into AndroidManifest.xml for

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

and into config.xml for iOS

<plugin name="NetworkStatus" value="CDVConnection" />

For other platforms see here

Bye...


No comments:

Post a Comment