如何在android中以编程方式启用/禁用蓝牙 [英] How to enable/disable bluetooth programmatically in android

查看:43
本文介绍了如何在android中以编程方式启用/禁用蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过程序启用/禁用蓝牙.我有以下代码.

I want to enable/disable bluetooth through the program. I have the following code.

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

但是此代码在 SDK 1.5 中不起作用.我怎样才能让它工作?

But this code is not working in SDK 1.5. How can I make it work?

推荐答案

Android BluetoothAdapter 文档说它从 API 级别 5 开始可用.API 级别 5 是 Android 2.0.

Android BluetoothAdapter docs say it has been available since API Level 5. API Level 5 is Android 2.0.

您可以尝试使用蓝牙API的backport(没有亲自尝试过):http://code.google.com/p/backport-android-bluetooth/

You can try using a backport of the Bluetooth API (have not tried it personally): http://code.google.com/p/backport-android-bluetooth/

这篇关于如何在android中以编程方式启用/禁用蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆