CrossBrowdy - Basic tutorial

Device

Proximity sensor

It is possible to get information from the proximity sensor of a device (through the Proximity Sensor API or the Proximity Sensor Events as "ondeviceproximity" or "onuserproximity" or compatible ones). Here is an example:


	//Proximity sensor management:
	if (CB_Device.Proximity.isSupported())
	{	
		CB_console("The proximity detection is supported (through the Proximity Sensor API or the Proximity Sensor Events as 'ondeviceproximity' or 'onuserproximity' or compatible ones).");
		
		//Gets the proximity now and also every time it changes:
		CB_Device.Proximity.onChange(function(data) { CB_console("Proximity detected: " + data.value); }); //Data will be normalized automatically.
	}
	else
	{
		CB_console("The proximity detection is not supported.");
	}

Note that CrossBrowdy will try to normalize automatically the data of the event object received to minimize the differences across different clients, so you will normally not have to worry about this.

Check the API documentation to read more about the CB_Device and the CB_Device.Proximity static classes.

Go back to Guides & Tutorials













Share