Monthly Archives: January 2011

Things you can do on Android that you can’t on iOS: Part 1 – Bluetooth and WiFi settings

Here’s my first in a (hopefully) multi-part series highlighting some of the unique things you can do in Android that you can’t on iOS.  First off, changing antenna settings.

In iOS, direct access to the Bluetooth stack requires a third party library, which violates the terms of the app store and risks rejection.  In Android, however, access to the Bluetooth stack is fully supported within Android.  Here’s a quick snippt of code that illuminates how to use the Bluetooth API’s:


public void turnOnBluetooth() {
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
if (!bt.isEnabled()) {
bt.enable();
}
}

The BluetoothAdapter can turn BT on or off; enable discovery; query devices, and more. There are a multitude of ways to use this. For example, there are a number of widgets in the app store that flip Bluetooth on or off as well as some neat unique applications that facilitate and automate bluetooth file transfers.

Likewise, Android includes an API to access Wifi connections. The Wifi API is shown here. See the snippet below:


public void toggleWifi() {
Context ctx = getApplicationContext();
WifiManager wifiMgr = (WifiManager)ctx.getSystemService(Context.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled())
wifiMgr.setWifiEnabled(false);
else
wifiMgr.setWifiEnabled(true);
}

Advertisements