Skip to content

Instantly share code, notes, and snippets.

View tylertreat's full-sized avatar

Tyler Treat tylertreat

View GitHub Profile
var socket = io.connect('/notifications');
socket.on('notifications', function(notification) {
notification = $.parseJSON(notification);
var eventName = notification.event_name;
var payload = notification.payload;
dispatcher.trigger(eventName, payload);
});
Intent intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivityForResult(intent, REQUEST_DEVICE_PAIR);
private BluetoothReceiver mBluetoothReceiver;
private BluetoothAdapter mBluetoothAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
...
// Register a BroadcastReceiver for Bluetooth Intents
mBluetoothReceiver = new BluetoothReceiver();
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
private class BluetoothReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Found a Bluetooth device
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
onDeviceFound(device); // Do something with it
} else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
// Discovery has started, display progress spinner
public boolean pairDevice(BluetoothDevice device) {
try {
Method createBond = BluetoothDevice.class.getMethod("createBond");
return (boolean) createBond.invoke(device);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
private class BluetoothReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Found a Bluetooth device
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
onDeviceFound(device); //Do something with it
} else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
// Device pairing/unpairing occurred
<bean id="fooBean" class="com.foo.bar.FooBean" />
@Component
public class FooBean {
// ...
}
for (Class<?> clazz : getClasspathClasses("com.foo.bar")) {
if (clazz.isAnnotationPresent(Component.class)) {
// Found bean
}
}