privatevalstartForResult=registerForActivityResult(ActivityResultContracts.StartActivityForResult()){result->if(result.resultCode==Activity.RESULT_OK){valintent:Intent?=result.dataToast.makeText(this,"RESULT_OK",Toast.LENGTH_LONG).show()// Handle the Intent
}}
privatefunbluetoothInit(){// bluetooth init
valbluetoothManager:BluetoothManager=getSystemService(BluetoothManager::class.java)valbluetoothAdapter:BluetoothAdapter?=bluetoothManager.adapter// check bluetoothAdapter
if(bluetoothAdapter==null){// Device doesn't support Bluetooth
Toast.makeText(this,"Device doesn't support Bluetooth.",Toast.LENGTH_LONG).show()}// get bluetooth
if(bluetoothAdapter?.isEnabled==false){Toast.makeText(this,"bluetoothAdapter is not enable",Toast.LENGTH_LONG).show()// Bluetooth を有効する
valintent=Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)startForResult.launch(intent)}}