일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 사드보복완화
- 국제유가
- 안드로이드
- 트럼프
- ruby
- 파이썬
- 어학·외국어
- 셀트리온
- englishwriting
- dataframe
- 주식시황
- 무역전쟁
- 시황
- LG전자
- 화승엔터프라이즈
- 다우산업
- Intent
- Java
- S&P
- Python
- e-mailwriting
- android
- 나스닥
- 금리인상
- 영어메일
- 네마녀의날
- toeice-mail
- 영어메일쓰기
- 토익이메일
- 다우
- Today
- Total
Developer MJ Story
[android/BT] OPP(Object Push Profile)를 활용한 file 전송 본문
android에서는 다양한 Bluetooth profile을 지원합니다.
그 중에서 오늘 알아볼 profile은 OPP(Object Push Profile)입니다.
Push라는 이름에서도 알 수 있듯이 단 방향 profile 입니다.
그 대신 사전pairing이 되어 있지 않아도 file을 바로push 할 수 있는 장점이 있습니다.
그래서 android내부 application에서 phone 간 파일을 공유할 때 사용하는 profile입니다.
아래 그림은 Gallery에서 사용하는 모습입니다.
OPP는 어떤 이유에서인지는 몰라도 anroid에서 개발자가 직접 BluetoothOppService에 접근할 수 없습니다.
그래서 우회적인 방법으로 Bluetooth OPP를 사용해야 합니다.
그렇다고 전혀 어렵지 않습니다.
물론 방법을 모르면…………………..답이 없는거죠??ㅋ
아래와 같은 함수 하나면 원하는 파일을 Bluetooth OPP로 전송 가능합니다.
그냥 intent 로 BluetoothOppService에 event를 전달하는 것입니다.
private void BtOppConnect(){
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
File file = new File("/storage/emulated/0/Download/1.jpg");
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.android.bluetooth");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(sharingIntent, "Share file"));
Log.d(TAG, "sendBroadcast");
}
위와 같이 intent를 던져 주면 아래 사진과 같이 BT device를 선택하는 화면이 나옴니다.
이때, 타겟 device를 선택하면 타겟 device로 Download/1.jpg라는 파일이 OPP를 통해 전송됩니다.
Android 내부적으로는 보다 복잡한 과정이 있지만, 복잡하므로 생략하겠습니다.
궁금하신 사항은 덧글로 남겨 주세요.
'Software > Android' 카테고리의 다른 글
[Android/basic] Android 4대 Components(Activity, Service) (0) | 2014.08.27 |
---|---|
[Android/basic] 가독성은 높이고, 수정을 쉽게 할 수 있는 Android Button event 등록 (0) | 2014.07.15 |
[Android/UDP] UDP socket을 이용한 message send/receive (0) | 2014.06.09 |
[Android/AsyncTask] AsyncTask 활용하기 (0) | 2014.06.09 |
[Android/ListView] Android ListView에 두 개의 아이템 표시하기(simple_list_item_2) (0) | 2014.06.09 |