对于此蓝牙活动,我将如何从startActivityForResult更改为registerForActivityResult?请帮助我,因为我是新的java和Android。我试过看视频和教程,但我只得到了更多的错误。如果你能给我任何建议,我将不胜感激。
//on btn click
mOnBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBlueAdapter.isEnabled()){
showToast("Turning On Bluetooth...");
//intent to on bluetooth
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, REQUEST_ENABLE_BT);
}
else {
showToast("Bluetooth is already on");
}
}
});发布于 2022-04-25 03:54:19
private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
}
}
launcher.launch(intent)发布于 2022-04-25 05:56:59
对于那些在中需要服务的人,可以使用
private ActivityResultLauncher<Intent> startForResult =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
});
startForResult.launch(intent);https://stackoverflow.com/questions/71993992
复制相似问题