2

Android BluetoothChatの例を編集して、複数のアクティビティで使用できるようにしたいと考えています。そのため、ここでアドバイスされているように、アプリケーションを拡張するクラスを作成しました

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 クラスから新しいアプリケーション クラスに移動することです。

すなわち

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

0 に答える 0