Skip to content

Instantly share code, notes, and snippets.

@georgioupanayiotis
Last active August 29, 2015 14:14
Show Gist options
  • Save georgioupanayiotis/0d33f9b6860e1a363de6 to your computer and use it in GitHub Desktop.
Save georgioupanayiotis/0d33f9b6860e1a363de6 to your computer and use it in GitHub Desktop.
Bluetooth Low Energy
<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:orientation="vertical"
android:layout_margin="20dp"
tools:context="com.bluetoothsupport.panayiotisgeorgiou.bluetoothsupport.MainActivity">
<TextView
android:id="@+id/manufacturer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"/>
<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>
To check if your device support Bluetooth Low Energy programmically, check (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)).
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.
package com.bluetoothsupport.panayiotisgeorgiou.runningservices;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
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");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment