Code Example‎ > ‎

Device Status



Device status is to check whether Bluetooth or Wi-Fi is turned on/off.

Create a new project

Choose File >>New>>Project under eclipse menu.
Then from the New Project Dialog, Select Droidget Wizard>>Project
Fill necessary fields including project name..etc..
In the Feature section , Click on Add and select Appconfig feature "http://bondi.omtp.org/api/devicestatus".   
Then Click Finish
Project with the given name will appear in the Eclipse project explorer.

Create a Javascript file

Under src folder, create another folder called ‘js’ and create a file called scripts.js under ‘js’ folder

  • Right click (Command click on Mac) on the Project name
  • Choose File >> New >> Folder and name it as js
  • Right click (Command click on Mac) on js foder , then File >> New >> File  and name it as scripts.js
// Get the status of Bluetooth
function getBtStatus(){
    var btStatus = bondi.devicestatus.getPropertyValue({aspect:'BluetoothHardware', property:'status'});
    document.getElementById("divMsg").innerHTML = "Bluetooth:" + btStatus;
}

// Bluetooth On
function setBtOn(){
    bondi.devicestatus.setPropertyValue({
            aspect: "BluetoothHardware",
            property: "status"
            }, "true");
}

// Bluetooth Off
function setBtOff(){
    bondi.devicestatus.setPropertyValue({
            aspect: "BluetoothHardware",
            property: "status"
            }, "false");
}

Bluetooth Status

Turn ON Bluetooth

bondi.devicestatus.setPropertyValue({
            aspect: "BluetoothHardware",
            property: "status"
            }, "true"); 

Turn OFF Bluetooth

bondi.devicestatus.setPropertyValue({
            aspect: "WiFiHardware",
            property: "status"
            }, "true"); 

Wi-Fi Status

Turn ON Wi-Fi

bondi.devicestatus.setPropertyValue({
            aspect: "WiFiHardware",
            property: "status"
            }, "true"); 


Turn OFF Wi-Fi

bondi.devicestatus.setPropertyValue({
            aspect: "WiFiHardware",
            property: "status"
            }, "false"); 


Get the current status of Wi-Fi

var wifiStatus = bondi.devicestatus.getPropertyValue({aspect:'WiFiHardware', property:'status'});

Edit index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <title>DevicestatusSample</title>
    <script type="text/javascript" src="js/script.js"></script>
</head>
<body>
    <button onclick="javascript:getBtStatus();">Get Status</button>
    <button onclick="javascript:setBtOn();">BT On</button>
    <button onclick="javascript:setBtOff();">BT Off</button><br>
    <div id="divMsg" style="color: yellow; height: 1.5em; font-size: 2em; "></div>
</body>
</html>

Edit config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget id="DevicestatusSample_1279632644871" version="1.0" width="300" height="200">
    <content src="index.html" type="text/html"/>
    <name>DevicestatusSample</name>
    <description>The Sample of AppConfig</description>
    <author url="http://www.gclue.jp">GClue</author>
    <icon src="icon.png"/>
    <license></license>
    <feature name="http://bondi.omtp.org/api/devicestatus" />
</widget>

Deploy the project

Now save and deploy the project
  • From the eclipse menu select Droidget --> packaging
  • Then Droidget-->install packaging
or 
upload the Widget to web server and update the download.html file as follows. Then access the download.html from the smart phone and 
install the widget from URI. 

Download.html
<html>
<head>
    <title>Download</title>
</head>
<body>
    <a href="droidget://www.example.com/DevicestatusSample.wgt">DevicestatusSample</a><br>
</body>
</html>

Preview



Comments