Java Android蓝牙启用错误
我正在开发一个具有蓝牙功能的android应用程序。但我有一个问题。我正在使用以下代码Java Android蓝牙启用错误,java,android,bluetooth,Java,Android,Bluetooth,我正在开发一个具有蓝牙功能的android应用程序。但我有一个问题。我正在使用以下代码 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth tv.setText("Device is not there"); setConten
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
tv.setText("Device is not there");
setContentView(tv);
}
else
{
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
tv.setText("Device is there");
setContentView(tv);
}
我犯了一个错误
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
每当我试图运行该代码时,我的应用程序就会显示一个带有“强制关闭”按钮的消息框,从而崩溃。错误在哪里,我还没有弄清楚。请帮忙。
问候阿萨拉姆·阿莱库姆·阿基。
我对安卓相当陌生,但是…你的清单中有这样的东西吗
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
`boolean hasBluetooth = (mBluetoothAdapter == null);`
if (hasBluetooth && !mBluetoothAdapter.isEnabled())
您的舱单中有正确的权限吗? 您需要指定您的应用程序将通过以下方式使用蓝牙:
<uses-permission android:name="android.permission.BLUETOOTH" />
在您的清单文件中。
如果使用Eclipse,清单文件将命名为AndroidManifest.xml,并且在项目文件夹中可见。Valaikum salam brother!我也是android新手,老实说,我不知道manifest是什么。通过浏览网页,我了解到这是您项目中的一个xml文件,它描述了android操作系统,您的应用程序将具有哪些功能。那么,我如何修改我的menifest以实现蓝牙的这种功能呢。谢谢。对不起,刚刚访问了你的个人资料,你确实是姐姐,再次对不起。但是如果你知道,请解决我的问题。我正在制作一个应用程序,你可以通过蓝牙连接的手机控制电脑的鼠标指针。我已经用两台个人电脑做了同样的,但现在用的是手机。这基本上是我的大学作业。是的,这就是我犯的错误,只是在我的清单中添加了上面的一行,然后解决了问题。谢谢兄弟。我得到的错误无法解决“请求启用”。是什么导致了这个错误?