일본인 개발자인 山本隆(야마모토 타카시)의 글을 참고해 안드로이드에서 블루투스 활성여부 조회와 설정하는 내용을 공유합니다.

블루투스 활성여부 조회

1
2
3
4
5
6
7
8
9
10
11
12
13
uses
  Androidapi.JNI.Bluetooth;
 
procedure TForm2.Button1Click(Sender: TObject);
var
  Adapter: JBluetoothAdapter;
begin
  Adapter := TJBluetoothAdapter.JavaClass.getDefaultAdapter;
  if Adapter.isEnabled then
    ShowMessage('Bluetooth가 활성화 되어있습니다.')
  else
    ShowMessage('Bluetooth가 활성화 되지 않았습니다.');
end;

블루투스 활성화 설정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
uses
  Androidapi.JNI.Bluetooth;
 
procedure TForm2.Button2Click(Sender: TObject);
var
  Adapter: JBluetoothAdapter;
begin
  Adapter := TJBluetoothAdapter.JavaClass.getDefaultAdapter;
  if Adapter.enable then
    ShowMessage('Bluetooth를 활성화합니다.')
  else
    ShowMessage('사용할 수 없습니다.');
end;
 
procedure TForm1.Button3Click(Sender: TObject);
var
  Adapter: JBluetoothAdapter;
begin
  Adapter := TJBluetoothAdapter.JavaClass.getDefaultAdapter;
  if Adapter.disable then
    ShowMessage('Bluetooth를 비활성화합니다.')
  else
    ShowMessage('사용할 수 없습니다.');
end;

블루투스 권한이 있는지 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
uses
  Androidapi.Helpers,
  Androidapi.JNI.GraphicsContentViewText;
 
procedure TForm2.Button3Click(Sender: TObject);
  function HasPermission(const Permission: string): Boolean;
  begin
    Result := SharedActivityContext.checkCallingOrSelfPermission(StringToJString(Permission)) = TJPackageManager.JavaClass.PERMISSION_GRANTED
  end;
 
begin
  if HasPermission('android.permission.BLUETOOTH') then
    ShowMessage('Bluetooth 통신 권한이 있습니다.')
  else
    ShowMessage('Bluetooth 통신 권한이 없습니다');
 
  if HasPermission('android.permission.BLUETOOTH_ADMIN') then
    ShowMessage('Bluetooth 설정 수정 권한이 있습니다.')
  else
    ShowMessage('Bluetooth 설정 수정 권한이 없습니다.');
end;

  • 블루투스 관련 권한(Project Options > Uses Permissions)이 필요합니다.
    • Bluetooth
    • Bluetooth admin

샘플프로그램 다운로드

 ProjectSetBluetooth.zip

참고 글

번호 제목 글쓴이 날짜 조회 수
공지 [DelphiCon 요약] 코드사이트 로깅 실전 활용 기법 (Real-world CodeSite Logging Techniques) 관리자 2021.01.19 17916
공지 [UX Summit 요약] 오른쪽 클릭은 옳다 (Right Click is Right) 관리자 2020.11.16 16268
공지 [10.4 시드니] What's NEW! 신기능 자세히 보기 관리자 2020.05.27 18907
공지 RAD스튜디오(델파이,C++빌더) - 고객 사례 목록 관리자 2018.10.23 24514
공지 [데브기어 컨설팅] 모바일 앱 & 업그레이드 마이그레이션 [1] 관리자 2017.02.06 25886
공지 [전체 목록] 이 달의 기술자료 & 기술레터 관리자 2017.02.06 21248
공지 RAD스튜디오(델파이, C++빌더) - 시작하기 [1] 관리자 2015.06.30 41833
공지 RAD스튜디오(델파이,C++빌더) - 모바일 앱 개발 사례 (2020년 11월 업데이트 됨) 험프리 2014.01.16 177129
34 [FireDAC Skill Sprints] 8. TFDMemTable: 메모리 기반 데이터셋 사용하기 Humphery 2015.04.06 2609
33 [FireDAC Skill Sprints] 9. LocalSQL: DB에서 가져온 데이터(데이터셋)를 대상으로 다시 SQL쿼리 실행하기 Humphery 2015.04.01 1937
32 [FireDAC Skill Sprints] 6. 전처리: SQL문을 유연하게 작성할 수 있는 Param와 Macro 사용하기 Humphery 2015.03.13 1714
31 [FireDAC Skill Sprints] 5. Cascading Options: 고급기능을 활용 할 수 있는 FireDAC 옵션 Humphery 2015.03.11 1332
30 [FireDAC Skill Sprints] 4. ArrayDML로 30배 빠르게 데이터 입력하기 Humphery 2015.03.11 1514
29 [FireDAC Skill Sprints] 2. FireDAC으로 DBMS 사용 내역 추적, 모니터링 하기 Humphery 2015.03.07 1560
28 [FireDAC Skill Sprints] 3. 캐쉬를 이용한 업데이트와 자동증가필드(Identity) 적용 Humphery 2015.03.07 1516
27 웹사이트의 인증서 오류를 무시하고 http 결과 조회하기(WinInet 이용) Humphery 2015.03.06 2121
26 안드로이드 하드웨어 백버튼 제어하기 Humphery 2015.02.25 2538
25 [VCL] TaskDialog 컴포넌트 소개 Humphery 2015.02.25 1107
24 [XE7] 안드로이드 WiFi 상태조회와 설정하기 Humphery 2015.02.12 1889
» [XE7] 안드로이드 블루투스 활성화 조회와 설정하기 [1] Humphery 2015.02.12 1778
22 [VCL] TaskDialog 컴포넌트 소개 Humphery 2015.02.03 930
21 델파이로 국제화된 다국어 애플리케이션 만들기 Humphery 2014.12.10 1969
20 VCL앱을 모바일앱으로 쉽게 확장할 수 있는 앱테더링 자세히 살펴보기! [3] Humphery 2014.11.11 3413
19 더 쉬운코드, 더 유연한 코드를 작성할 수 있는 현대식 문법 [1] Humphery 2014.11.06 4636
18 [BaaS] VCL에서 특정사용자에게 GCM/APN 전송하기(FMX도 사용가능) Humphery 2014.07.25 1737
17 파이어몽키 모바일에서 사용자 파일 배포 및 사용 file 험프리 2013.12.27 6244
16 Runtime Packages 옵션으로 프로그램(배포) 용량 줄이기 [4] file Humphery 2013.12.19 7801
15 웹상의 이미지를 폼(TImage)에서 사용하는 방법 [3] file Humphery 2013.12.14 11841