Page 83 - MDP2022-2
P. 83
void bluetoothOn() {
if (mBluetoothAdapter == null) {
Toast.makeText(getApplicationContext(), "블루투스를 지원하지 않는 기기입니
다.", Toast.LENGTH_LONG).show();
} else {
if (mBluetoothAdapter.isEnabled()) {
Toast.makeText(getApplicationContext(), "블루투스가 이미 활성화 되어 있
습니다.", Toast.LENGTH_LONG).show();
mTvBluetoothStatus.setText("활성화");
} else {
Toast.makeText(getApplicationContext(), "블루투스가 활성화 되어 있지 않
습니다.", Toast.LENGTH_LONG).show();
Intent intentBluetoothEnable = new Intent(BluetoothAdapter.ACTION_REQ
UEST_ENABLE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETO
OTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String
[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See th
e documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivityForResult(intentBluetoothEnable, BT_REQUEST_ENABLE);
}
}
}
void bluetoothOff() {
if (mBluetoothAdapter.isEnabled()) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOT
H_CONNECT) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] pe
rmissions,