BluetoothAdapter.getDefaultAdapter()抛出异常 [英] BluetoothAdapter.getDefaultAdapter() throws exception

查看:5104
本文介绍了BluetoothAdapter.getDefaultAdapter()抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试蓝牙添加到我的libgdx Android项目。
我增加了以下到Android清单:

I try to add Bluetooth to my libgdx android project. I added the following to the Android manifest:

   <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
   <uses-permission android:name="android.permission.BLUETOOTH" />

我试图运行

   mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

在非活动课 - 例外。
我已阅读,班级应该是活动类。
好的。我创建

in non activity class - exception . I have read that the class should be activity class. Okay. I have created

   public class BluetoothServer extends Activity {
    ...
       public void GetBluetoothAdapter () {
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
      }
    }

我跑,如下所示:

I ran it as follows:

BluetoothServer.GetBluetoothAdapter()

在同一个地方再次崩溃。
我试图在两个设备的蓝牙车载。
当然,蓝牙这些设备上启用。
我不知道该怎么做。

Crashes again in the same place. I tried on two devices with Bluetooth onboard. Of course, Bluetooth is enabled on these devices. I have no idea what to do.

感谢。

推荐答案

这将大大有助于如果你能得到飞机失事的原因。出于某种原因,你似乎不能够访问堆栈跟踪,至少尝试此看到崩溃的原因:

It would help greatly if you could get the reason for the crash. For some reason you seem not able to access stacktrace, try at least this to see the crash reason:

...
try {
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
} catch (Exception e) {

    Toast toast = Toast.makeText(getApplicationContext(), e.getMessage(), 1000);
    toast.show();
}
...

这篇关于BluetoothAdapter.getDefaultAdapter()抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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