Skip to content

Commit

Permalink
Fix bug with permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
isradeleon committed Nov 21, 2019
1 parent 2187517 commit 3aeb7dd
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.application.isradeleon.thermalprinter.adapters.DevicesAdapter
import kotlinx.android.synthetic.main.activity_connect_printer.*
import java.lang.IllegalArgumentException

class ConnectBluetoothActivity : AppCompatActivity() {
val BLUETOOTH_PERMISSION = 76
Expand Down Expand Up @@ -82,14 +83,22 @@ class ConnectBluetoothActivity : AppCompatActivity() {
}

override fun onDestroy() {
unregisterReceiver(broadcastReceiver)
try{
unregisterReceiver(broadcastReceiver)
}catch (e: IllegalArgumentException){
e.printStackTrace()
}
super.onDestroy()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if(requestCode == BLUETOOTH_PERMISSION){
if(resultCode == RESULT_OK){
if(hasAllPermissions()){
findDevices()
}else{
finish()
Expand Down

0 comments on commit 3aeb7dd

Please sign in to comment.