이 튜토리얼에서는 Android 기기의 현재 Bluetooth 어댑터가 LE 2M PHY(Bluetooth Low Energy 2M PHY)를 지원하는지 확인하는 방법을 예제를 통해 살펴봅니다.
LE 2M PHY는 Bluetooth 5에서 새롭게 도입된 물리 계층(PHY)으로, BLE(저전력 블루투스) 연결의 데이터 전송 속도를 기존 1Mbps에서 2Mbps로 두 배 향상시켜 주는 기능입니다. 이 기능의 지원 여부는 Android 8.0(API 레벨 26) 이상에서 제공되는 isLe2MPhySupported() 메서드를 호출하여 간단히 확인할 수 있습니다.
1단계 — 새 프로젝트 만들기
Android Studio에서 File ⇒ New Project를 선택해 새 프로젝트를 생성하고, 필요한 정보를 모두 입력합니다.
2단계 — 레이아웃 파일 수정
res/layout/activity_main.xml 파일에 아래 코드를 추가합니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>위 코드에서는 화면에 배치된 TextView를 사용해 LE 2M PHY 지원 여부 결과를 표시합니다.
3단계 — MainActivity.java 작성
src/MainActivity.java 파일에 아래 코드를 추가합니다.
package com.example.myapplication;
import android.bluetooth.BluetoothManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.text);
final BluetoothManager manager =
(BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
// LE 2M PHY 지원 여부는 Android 8.0(API 26)부터 확인할 수 있습니다.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
textView.setText("" + manager.getAdapter().isLe2MPhySupported());
}
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onResume() {
super.onResume();
}
}핵심은 getSystemService(BLUETOOTH_SERVICE)로 BluetoothManager를 가져온 뒤, manager.getAdapter().isLe2MPhySupported()를 호출하는 부분입니다. 이 메서드는 기기가 LE 2M PHY를 지원하면 true, 그렇지 않으면 false를 반환하며, 그 결과가 TextView에 그대로 출력됩니다.
4단계 — AndroidManifest.xml 설정
androidManifest.xml 파일에 아래와 같이 Bluetooth 관련 권한을 선언합니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>앱 실행 및 결과 확인
이제 애플리케이션을 실행해 보겠습니다. 실제 Android 휴대폰이 컴퓨터에 연결되어 있다고 가정합니다. Android Studio에서 프로젝트의 액티비티 파일 중 하나를 연 후, 툴바의 Run 아이콘을 클릭하세요. 옵션 목록에서 휴대폰 기기를 선택하면, 모바일 기기 화면에 아래와 같은 결과가 표시됩니다.

BLE 2M PHY를 지원하는 기기라면 화면에 true가, 지원하지 않는 기기라면 false가 출력됩니다. 참고로 이 외에도 isLeCodedPhySupported(), isExtendedAdvertisingSupported() 등 BluetoothAdapter의 유사한 메서드들을 활용하면 기기의 다양한 Bluetooth 5 기능 지원 여부도 함께 확인할 수 있습니다.