【问题标题】:Bluetooth chat BluetoothService.this.start() error and mchatservice,start() error蓝牙聊天 BluetoothService.this.start() 错误和 mchatservice,start() 错误
【发布时间】:2015-12-27 15:16:48
【问题描述】:

Bluetooth chat sample

您好,我正在尝试蓝牙聊天,但出现此错误无法解析方法 start();对彼此而言。有谁知道怎么回事?

BluetoothData_display Java file Bluetooth Service Java

所以我得到的 BluetoothService.start() 错误在此蓝牙服务 java 链接中,而 mchatservice 错误在此 BluetoothData_display Java 链接中。我使用了蓝牙聊天示例代码,并更改了其中的一些代码。

【问题讨论】:

  • 能否请您提供更多详细信息? mChatService 和 BluetoothService 是什么?
  • 嗨@AndroidDev 代码是BluetoothChat 示例。代码很长,所以我放了它的链接。
  • @AndroidDev 在 Bluetoothchatfragment 和 Bluetoothchat 服务下。
  • @AndroidDev 嗨对不起忽略代码。我忘了我修改它。我会再上传一个
  • 所以你正在构建提到的蓝牙聊天示例的代码,对吧?

标签: android bluetooth


【解决方案1】:

我浏览了你上面提到的代码示例,我发现你没有定义start()(它包含在示例代码的BluetoothChatService中)方法BluetoothService 内(您已上传到 Dropbox)

这里是BluetoothChatServicestart()方法。根据你的修改。

public synchronized void start() {
    Log.d(TAG, "start");

    // Cancel any thread attempting to make a connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
        mConnectedThread.cancel();
        mConnectedThread = null;
    }

    setState(STATE_LISTEN);

    // Start the thread to listen on a BluetoothServerSocket
    if (mSecureAcceptThread == null) {
        mSecureAcceptThread = new AcceptThread(true);
        mSecureAcceptThread.start();
    }
    if (mInsecureAcceptThread == null) {
        mInsecureAcceptThread = new AcceptThread(false);
        mInsecureAcceptThread.start();
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-18
相关资源
最近更新 更多