Android
안드로이드 기기의 블루투스 지원여부 확인하기.
일용직 코딩노동자
2019. 12. 30. 15:04
728x90
반응형
public static BluetoothAdapter bluetoothAdapter;
public BluetoothService(Activity activity) { //생성자입니다.
this.activity = activity;
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
public static boolean getDeviceState() { //블루투스가 지원되는 기기인지 지원이 되지않는 기기인지 판별
if(bluetoothAdapter == null) return false;
else return true;
}
getDevicesState 메소드에서 ture가 반환되면 지원이 가능한 기기.
false가 반환되면 지원이 되지않는 기기입니다.
사용할 메인클래스에서
public static Context mContext;
mContext = this;
if(bluetoothService == null) bluetoothService = new BluetoothService((Activity) mContext);
if(BluetoothService.getDeviceState()) {}//블루투스가 지원이되는 기기인지 판별
else {
Toast.makeText(getApplicationContext(),"기기가 블루투스를 지원하지 않아 앱이 종료됩니다.",Toast.LENGTH_SHORT).show();
finish();
}
궁금하신 사항은 댓글 남겨주세요.
728x90
반응형