Posts

Showing posts with the label example

Bluetooth LE Gatt Example step by step

Image
Bluetooth LE Gatt Example step by step Last post demonstrate the Android Bluetooth Le Gatt example code with Arduino/Genuino 101. This post start to (TRY to) implement my own Bluetooth LE Gatt Example, step-by-step. The aim of the examples (in coming series) are scan BLE device, find and link with specified device Genuino 101 (programmed with "LEDCB", refer previous post), and read and write characteristic of the device to turn ON/OFF the Genuino 101 on-board LED. The main reference material are: - Android Developers Guide > Bluetooth Low Energy - The Android example code - BluetoothLeGatt. (The example in last post) In this first step, create a new project in Android Studio, named AndroidBleGatt. In my example (in coming post) I will scan LE device using BluetoothLeScanner (Added in API level 21) instead of calling deprecated startLeScan() and stopLeScan() methods as in the BluetoothLeGatt example, so specify the Min Sdk Version of API 21. Edit AndroidManifest.xm...

Bluetooth LE example connect to Bluetooth LE device and display GATT Services

Image
Bluetooth LE example connect to Bluetooth LE device and display GATT Services Last post of Bluetooth LE example show how to "Scan specified BLE devices with ScanFilter". This post show how to connect to the device and display the supported service by the device. Modify from last "Scan specified BLE devices with ScanFilter". Basically this part copy from "example code of Bluetooth Le Gatt", refer to "Bluetooth Le Gatt example to link with Arduino/Genuino 101". Create a new activity ControlActivity.java package com.blogspot.android_er.androidblegatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.support.annota...

Bluetooth LE Gatt Example scan BLE devices

Image
Bluetooth LE Gatt Example scan BLE devices Last post show the first step to enable Bluetooth, this post show how to scan BLE devices in range. We will re-use the BluetoothLeService.java in Android example code "Bluetooth Le Gatt example". Modify to suit our case. BluetoothLeService.java /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.blogspot.android_er.androidblegatt; import android.app....

BottomSheetDialog example

Image
BottomSheetDialog example The former post show a example of "Implement BottomSheet of Android Design Support Library". This post show a BottomSheetDialog example. To use Design Support Library in your app, you have to "Add Android Design Support Library to Android Studio Project", currently version com.android.support:design:23.4.0. Create a file layout/bottomsheetdialog_layout.xml, to define the layout of the BottomSheetDialog. <?xml version="1.0" encoding="utf-8"?> <LinearLayout android_orientation="vertical" android_layout_width="match_parent" android_layout_height="wrap_content" app_layout_behavior="android.support.design.widget.BottomSheetBehavior"> <LinearLayout android_layout_width="match_parent" android_layout_height="300dp" android_orientation="vertical"> <TextView android_layout_width="wrap_content" android_layout_height=...

Bluetooth Le Gatt example to link with Arduino Genuino 101

Image
Bluetooth Le Gatt example to link with Arduino Genuino 101 This post show how to run the Android Bluetooth Le Gatt example Code to link with Arduino/Genuino 101. The Arduino/Genuino 101 board contains the Intel� Curie� Module. The 101 adds Bluetooth Low Energy capabilities and has an on-board 6-axis accelerometer/gyroscope, providing exciting opportunities for building creative projects in the connected world. More information about the technical specifications and documentation can be found on the Arduino/Genuino 101 main page. In Arduino/Genuino 101 board, program with example: > File > Examples > CurieBLE > CallbackLED This example setup Arduino/Genuino 101 as Bluetooth LE device (named "LEDCB") with service with UUID "19B10000-E8F2-537E-4F6C-D104768A1214" and create switch characteristic allowing remote device to read and write, with UUID "19B10001-E8F2-537E-4F6C-D104768A1214". We need the UUIDs in future examples. So I copy here for future...

Boon JSON Custom object serializer now works with super classes and interfaces Example of using Guava HashCode

Boon JSON Custom object serializer now works with super classes and interfaces Example of using Guava HashCode related to https://github.com/RichardHightower/boon/issues/242 https://github.com/RichardHightower/boon/issues/231 Boon JSON: Custom object serializer works with super classes, and interfaces (and example of using HashCodeGuava).  Lets say you want to write a custom object serializer to work with Guava HashCode thingy or whatever else you need. public static String toJson ( Object obj ) { return createSerializer (). serialize ( obj ). toString (); } private static JsonSerializer createSerializer () { JsonSerializerFactory factory = new JsonSerializerFactory () . addTypeSerializer ( HashCode . class , new HashCodeSerializer () ); return factory . create (); } private static class HashCodeSerializer implements CustomObjectSerializer < HashCode > { @Override public Class < HashCode > type () { return HashCode . class ; } @...