作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
我正在尝试使用以下我必须测试的代码来解决问题:我正在使用 Mockito 和 Robotium 来解决大多数测试用例。问题是通过以下方式启动的请求对话框来模拟用户的回答: Intent enableB
根据开发者指南,可以请求启用蓝牙: http://developer.android.com/guide/topics/connectivity/bluetooth.html#SettingUp if
if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION
我是一名优秀的程序员,十分优秀!