2

我想编辑 Android BluetoothChat示例以便能够将它与多个活动一起使用。因此,我创建了一个类,按照此处的建议扩展 Application

public class cBaseApplication extends Application {

    public static cBaseApplication context;

    private BluetoothChatService mBluetoothConnectedThread;

    // Local Bluetooth adapter
    private static BluetoothAdapter mBluetoothAdapter = null;

    @Override
    public void onCreate() {
        super.onCreate();

        context = this;

        // Get local Bluetooth adapter
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    public BluetoothChatService getBluetoothConnectedThread() {
        return mBluetoothConnectedThread;
    }

    public void setBluetoothConnectedThread(BluetoothChatService mBluetoothConnectedThread) {
        this.mBluetoothConnectedThread = mBluetoothConnectedThread;
    }

    public static BluetoothAdapter getBluetoothAdapter() {
        return mBluetoothAdapter;
    }

}

我遇到的问题是:将所需的代码从原始的 BluetoothChat 类移动到新的应用程序类。

IE

// Initialize the BluetoothChatService to perform bluetooth connections
        mChatService = new BluetoothChatService(this, mHandler);
4

0 回答 0