gpt4 book ai didi

android - 我们可以通过 REQUEST_ENABLE_BT 那么 ACTION_REQUEST_ENABLE 的 Intent 需要什么

转载 作者:行者123 更新时间:2023-11-29 20:13:38 24 4
gpt4 key购买 nike

if (!mBluetoothAdapter.isEnabled()) 
{
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

为什么我们不能使用单个常量 REQUEST_ENABLE_BT 启用蓝牙

最佳答案

此行向用户呈现“启用蓝牙”操作。所以在这里你要设置你的 Intent 的 Action 。

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

这一行通过 id REQUEST_ENABLE_BT 设置要返回的结果,这只是您在类中本地定义的一个 int。这可以是任何东西。它不必被称为 REQUEST_ENABLE_BT...您完全可以传入任何 int,然后在获得结果时对其进行过滤。

startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

所以在接收结果的 Activity 中,它看起来像这样:

protected void onActivityResult (int requestCode, int resultCode, Intent data) {
//int requestCode would equal REQUEST_ENABLE_BT in your case
//so you would test to make sure this is the result you want by testing
//to see if requestCode == REQUEST_ENABLE_BT
}

关于android - 我们可以通过 REQUEST_ENABLE_BT 那么 ACTION_REQUEST_ENABLE 的 Intent 需要什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34401017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com