Saturday, March 14, 2015

How to use Classic Bluetooth on iOS

Something like classic Bluetooth sounds like it should be simple enough to use on iOS. I recently falsely stated is was all there and ready to go in the Core Bluetooth APIs. Although Bluetooth LE is fully accessible, classic Bluetooth is not. But there are a few options developers can explore if they need to use Classic Bluetooth within an application.

The first thing to note is, pairing with a Classic Bluetooth device is handled at the OS level, so there isn’t any way we can start the connection or pairing process from within an app.

So assuming a device is already paired, we have a few options:

 

External Accessory Framework

https://developer.apple.com/library/prerelease/ios/documentation/ExternalAccessory/Reference/ExternalAccessoryFrameworkReference/index.html

The External Accessory Framework is used to communicate with devices that are Apple MFi certified. MFi stands for “Made For i(phone/pad/pod)”. These devices can be physically connected, or connected over Bluetooth. If your device is MFi certified, this is the way to go.

As developers, you’re not required to join the MFi Program, that’s only necessary if you intend to develop hardware.

And of course, the External Accessory Framework APIs will not work with non-MFi devices.

 

Bluetooth Manager Framework

The Bluetooth Manager Framework sounds like the perfect solution to communicate with non-MFi Bluetooth Devices. Unfortunately, it’s a private API, meaning if you want to get your app published on the App Store, it can’t be used.

However, it can do things like scan for local devices, manage connections, and communicate with paired devices. Because it’s a private API, you won’t find any official Apple documentation but a quick Google search should get you going. There’s a good Objective-C tutorial here:

https://github.com/michaeldorner/BeeTee

 

GameKit

If you’re looking to connect two iOS devices, GameKit has a straight forward solution. It’s a simple matter of starting up GameKit, searching for local devices, connect, and then send/receive data. However, this is only for iOS device-to-device communication:

https://developer.apple.com/library/ios/documentation/GameKit/Reference/GameKit_Collection/index.html

 

BTstack

If you’re willing to Jailbreak your device and write applications that will never make it onto the App Store, you can make use of BTstack. The packages are available on Cydia. I’ve personally never used it but you can find more information here:

https://code.google.com/p/btstack/wiki/GettingStarted

 

Bluetooth 4.0

And finally, if your hardware is Bluetooth 4.0 compatible, you should probably consider moving away from Bluetooth Classic and using Bluetooth LE. Although BLE supports “casual” connections, it can also pair devices and establish secure connections.

This is also the path that Apple recommends, it’s well documented, stable on devices made in the last 2-3 years (iPhone 5 and up, iPad 3 and up), and fully defined in the CoreBluetooth APIs:

https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/CoreBluetooth_Framework/

Monday, March 2, 2015

Using the Dell Venue 8-7000 for Android Development

 

Introduction

I’ve been lucky enough to get my hands on a shiny new Dell Venue 8-7000 - and it’s a fantastic tablet. I’m slightly sad to say it’s going to be replacing my trusty Lenovo S8-50 tab. It’s been a fantastic device but you just can’t argue with the extra performance, or the 2560x1600 screen on the Dell. But this isn’t meant to be a review or a comparison. If you’re looking for a quick opinion, I’d absolutely recommend either tablet. The Venue 8-7000 is a beautiful high-end device, and the Lenovo S8-50 is shockingly good at its price point.

But the point of this post is to get to work (developing) on the Dell Venue 8-7000. Something that surprisingly doesn’t work “out of the box” on Windows.

 

The Problem? Drivers

To use an Android device for debugging on Windows, you need to have the correct drivers installed.  For Nexus devices, you can simply download the “Google USB Driver” via the Android SDK manager. And occasionally, such as with most Samsung Android devices, you need to download drivers directly from the developer’s website.

Unfortunately the Google USB Drivers don’t work, and when searching Dell’s website for drivers or downloads, there aren’t any.

dell-venue-downloads

 

The Fix? Hack the Google Drivers

Before I go on, there is a warning. You’ll need to configure your Windows system to allow unsigned drivers to be installed. This is because the checksum for the driver is no longer going to be correct after we edit it. I’m not going to cover that here, but a simple Google search will take you through the steps if you’re running Windows 8.1.

http://lmgtfy.com/?q=windows+8.1+install+unsigned+driver

Step 1 – obtain a copy of the Google USB Drivers

If you’ve downloaded them already using the SDK manager, simply navigate to your installed location. If you’re a Xamarin developer it’s typically c:\Users\[user name]\AppData\Local\Android\android-sdk\extras\google\usb_driver. Remember that the “Local” folder is hidden by default.

Alternatively, you can download the driver directly from here:

http://developer.android.com/sdk/win-usb.html

Copy this folder to another location since we’re going to modify it.

 

Step 2 – Enable Developer Options and USB Debugging

  1. Open Settings on the Venue 8
  2. Scroll to the bottom and click “About tablet”
  3. Tap on the Build number 7 times (to enable the Developer options)
  4. Go back one screen to Settings – you should now see “Developer options” above “About tablet”
  5. Open Developer options and check “USB Debugging”  
Step 3 – Configure the Dell Venue 8-7000
  1. Open Settings
  2. Select “Storage”
  3. Tap on the context menu in the upper right corner (three vertical dots)
  4. Select “USB computer connection” (it’s likely the only option
  5. Change the “CONNECT AS” option to “Camera (PTP)”
Step 4 – Get your Dell Venue 8’s device IDs
  1. Plug in your Dell Tablet to your Windows PC
  2. Open the Control Panel
  3. Open the Device Manager
  4. Expand “Other devices” and select “Android”
  5. On the Details tab, change the property to Hardware Ids and save them both
  6. Repeat steps 4 & 5 for the “MTP” entry under “Other devices” and save/record the IDs

device-man

 

hardware-ids

Step 5 – Modify the USB Drivers

  1. Open the location of your saved drivers
  2. Open “android_winusb.inf” with your favourite text editor
  3. Find the [Google.NTx86] section
  4. Add the two “Android” ids as %CompositeAdbInterface% entries
  5. Add the “MTP” ids as %SingleBootLoaderInterface% and %SingleAdbInterface%
  6. Scroll down to the [Google.NTamd64] and add the same four entries
  7. Save the inf file

It should look something like this:

[Google.NTx86]
;Dell Venue 8 7840
%CompositeAdbInterface% = USB_Install, USB\VID_8087&PID_0A5D&REV_FFFF
%CompositeAdbInterface% = USB_Install, USB\VID_8087&PID_0A5D
%SingleBootLoaderInterface% = USB_Install, USB\VID_413C&PID_B14D&MI_01
%SingleAdbInterface% = USB_Install, USB\VID_413C&PID_B14D&REV_FFFF&MI_01

Step 6 – Update the Drivers

  1. Open the Device Manager again on your PC with Tablet plugged in
  2. Right-click on the “Android” entry under “Other devices” and select “Update Driver Software”
  3. Browse to your modified driver and install
  4. Repeat for the “MDP” entry

*Remember – you must be able to install unsigned drivers

 

Step 7 – Run and Debug apps on your new tablet

You’ll now see two new entries in the device manager. Under “Portable Devices” you should see something like “Venue 8 7840” (the specific number will vary based on the model). You’ll also see an “Android ADB interface” entry, on my system it’s listed under “SAMSUNG Android Phone”.

Device-man-installed

If everything worked you should be ready to develop! My Venue 8-7000 is showing up correctly in Visual Studio 2013, Xamarin Studio for Windows, and Android Studio. 

working_sm