Sunday, December 7, 2014

Check if your Android device support Bluetooth Low Energy

Android 4.3 (API Level 18) introduces built-in platform support for Bluetooth Low Energy in the central role and provides APIs that apps can use to discover devices, query for services, and read/write characteristics.

To check if your device support Bluetooth Low Energy programmically, check (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)).

Nexus 7, 1st gen, not support BlueTooth LE!
MK 908III Android mini PC support both Bluetooth and Bluetooth LE


package com.example.androidcheckbtle;

import android.support.v7.app.ActionBarActivity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  TextView textManufacturer = (TextView)findViewById(R.id.manufacturer);
  TextView textModel = (TextView)findViewById(R.id.model);
  TextView textSupportBT = (TextView)findViewById(R.id.supportbt);
  TextView textSupportBTLE = (TextView)findViewById(R.id.supportbtle);
  
  //Get brand, manufacturer and model of your device
  textManufacturer.setText(Build.BRAND + " : " + Build.MANUFACTURER);
  textModel.setText(Build.MODEL);
  
  //Check if your device support BlueTooth
  if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)){
   textSupportBT.setText("Support BLUETOOTH");
  }else{
   textSupportBT.setText("NOT Support BLUETOOTH");
  }
  
  //Check if your device support Bluetooth Low Energy
  if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)){
   textSupportBTLE.setText("Support BLUETOOTH_LE");
  }else{
   textSupportBTLE.setText("NOT Support BLUETOOTH_LE");
  }
 }

}

/res/layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.androidcheckbtle.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:text="http://android-er.blogspot.com/"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/manufacturer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/model"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/supportbt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/supportbtle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
</LinearLayout>

No comments: