如何将此蓝牙 Activity 从 startActivityForResult 更改为 registerForActivityResult?请帮助我,因为我是 java 和 Android Studio 的新手。我曾尝试观看视频和教程,但只会收到更多错误。如果您能给我任何提示,我们将不胜感激。
//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");
}
}
});
最佳答案
private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
}
}
launcher.launch(intent)
关于java - 安卓工作室 : change from startActivityForResult to registerForActivityResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71993992/