일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- ViewGroup
- Retrofit2
- function scope
- java
- 안드로이드
- http
- LinearLayout
- linux
- javascript
- ConstraintLayout
- cardview
- permission
- vim
- Anro Coroutines
- block scope
- RecyclerView
- component
- layout
- react
- .kt
- RelativeLayout
- Eclipse
- intent
- ReactDOM
- view
- Anko SQLite
- Kotlin
- android
- props
- Git
- Today
- Total
이것저것 다 개발
[Android] Bluetooth Permission 설정 및 활성화 본문
Bluetooth Permission 설정 및 활성화하는법 입니다.
Bluetooth permission은 Normal Permission으로 Manifest에서만 설정해주면 됩니다.
먼저 AndroidManifest.xml에서 권한을 추가해줍니다.
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
다음으로 Activity에서 BluetoothAdapter 인스턴스를 생성해줍니다.
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
Bluetooth를 지원하는 단말인지 체크하겠습니다.
if (mBluetoothAdapter == null) {
Toast.makeText(this, "블루투스 미지원 단말입니다.", Toast.LENGTH_SHORT).show()
finish()
return
}
Bluetooth를 활성화하는 메소드를 만들겠습니다.
fun checkEnableBluetooth() {
// 블루투스 활성화 코드
if (mBluetoothAdapter.isEnabled) {
Log.d(TAG, "bluetooth is enabled")
} else {
Log.d(TAG, "bluetooth is disabled")
// bluetooth 활성화 코드 (확인 x)
// bluetoothAdapter!!.enable()
// bluetooth 활성화 코드 (확인 o)
var intent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
startActivityForResult(intent, REQUEST_ENABLE_BT)
}
}
## 위 코드는 코틀린으로 코딩된 소스입니다 ##
'Android' 카테고리의 다른 글
[Android] 부팅 시 실행되는 Service App 만들기 (0) | 2018.04.05 |
---|---|
[Android] System Permission (0) | 2018.04.05 |
[Android] AVD Custom Skin 사용하기(Custom Device) (0) | 2018.02.22 |
[Android] DPI 와 DP (0) | 2018.01.31 |
[Android] AlwaysOpenDrawer (0) | 2018.01.31 |