From 02117ec0a98e68092e0bbce852fd910402562c23 Mon Sep 17 00:00:00 2001 From: neilyhe <228429803@qq.com> Date: Fri, 21 Jun 2024 10:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=9D=83=E9=99=90=E7=94=B3?= =?UTF-8?q?=E8=AF=B7code=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../explorer/link/kitlink/activity/BaseActivity.kt | 12 ++++++++++-- .../link/kitlink/activity/DeviceCategoryActivity.kt | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/BaseActivity.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/BaseActivity.kt index 9d1af93ec..dbf4f3524 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/BaseActivity.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/BaseActivity.kt @@ -253,7 +253,10 @@ abstract class BaseActivity : AppCompatActivity() { return true } - protected fun requestPermission(permissions: Array, requestCode: Int = 102) { + protected fun requestPermission( + permissions: Array, + requestCode: Int = DEFAULT_REQUEST_PERMISSIONS_CODE + ) { ActivityCompat.requestPermissions(this, permissions, requestCode) } @@ -263,7 +266,7 @@ abstract class BaseActivity : AppCompatActivity() { grantResults: IntArray ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) - if (requestCode == 102 || requestCode == 103) { + if (requestCode == DEFAULT_REQUEST_PERMISSIONS_CODE || requestCode == REQUEST_BLUETOOTH_PERMISSIONS_CODE) { for (i in permissions.indices) { if (grantResults[i] == PackageManager.PERMISSION_DENIED) { permissionDenied(permissions[i]) @@ -357,4 +360,9 @@ abstract class BaseActivity : AppCompatActivity() { } }) } + + companion object{ + const val DEFAULT_REQUEST_PERMISSIONS_CODE = 102 //默认权限申请code码 + const val REQUEST_BLUETOOTH_PERMISSIONS_CODE = 104 //蓝牙权限申请code码 + } } diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt index 62b43d1cb..82a75237e 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt @@ -360,7 +360,7 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI grantResults: IntArray ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) - if (requestCode == 102) { + if (requestCode == DEFAULT_REQUEST_PERMISSIONS_CODE) { permissionDialog?.dismiss() permissionDialog = null for (i in permissions.indices) { @@ -582,7 +582,7 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI not_found_dev.visibility = View.GONE return } - requestPermission(permissions, 103) + requestPermission(permissions, REQUEST_BLUETOOTH_PERMISSIONS_CODE) permissionDialog = PermissionDialog(this@DeviceCategoryActivity, R.mipmap.permission_location ,getString(R.string.permission_location_lips), getString(R.string.permission_location_ssid_ble)) permissionDialog!!.show()