import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.util.Log; public class BluetoothService { private static Context mContext; private static BluetoothAdapter mBluetoothAdapter; public BluetoothService(Context context, BluetoothAdapter bluetoothAdapter){ mContext = context; mBluetoothAdapter = bluetoothAdapter; } //디바이스가 블루투스를 지원하는가? public static boolean deviceSupport(){ if(mBluetoothAdapter != null){ return true; } return false; } // 블루투스가 현재 활성화 되어있는가? public static boolean connectState(){ if(mBluetoothAdapter.isEnabled()){ return true; } return false; } // 블루투스 활성화 public static void enableBluetooth(){ if(!mBluetoothAdapter.isEnabled()){ mBluetoothAdapter.enable(); Log.d("Bluetooth", "On"); } } // 블루투스 비활성화 public static void disableBluetooth(){ if(mBluetoothAdapter.isEnabled()){ mBluetoothAdapter.disable(); Log.d("Bluetooth", "Off"); } } }
'Before 2022 > Android' 카테고리의 다른 글
안드로이드 소프트 키 제어 (0) | 2018.12.12 |
---|---|
안드로이드 현재 단말기가 더블 유심일 경우 전화번호를 가져오는 메소드 (0) | 2018.12.10 |
List to AlertDialog (0) | 2018.12.04 |
라이프 사이클 개념도 (0) | 2018.12.04 |
Flag Activity(Intent Flag 정리) (0) | 2018.09.02 |