connectivity-samples icon indicating copy to clipboard operation
connectivity-samples copied to clipboard

Error: cannot find symbol variable MESSAGE_READ and other

Open BiKit opened this issue 5 years ago • 1 comments

I'm on Android Studio 3.3.2, it's my first project using it and I got a problem, I got the errors:

"error: cannot find symbol variable MESSAGE_STATE_CHANGE" "error: cannot find symbol variable MESSAGE_WRITE" "error: cannot find symbol variable MESSAGE_READ" "error: cannot find symbol variable MESSAGE_DEVICE_NAME" "error: cannot find symbol variable DEVICE_NAME" "error: cannot find symbol variable MESSAGE_TOAST"

From this part of the code:

 private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        FragmentActivity activity = getActivity();
        switch (msg.what) {
            case Constants.MESSAGE_STATE_CHANGE:
                switch (msg.arg1) {
                    case BluetoothChatService.STATE_CONNECTED:
                        setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
                        mConversationArrayAdapter.clear();
                        break;
                    case BluetoothChatService.STATE_CONNECTING:
                        setStatus(R.string.title_connecting);
                        break;
                    case BluetoothChatService.STATE_LISTEN:
                    case BluetoothChatService.STATE_NONE:
                        setStatus(R.string.title_not_connected);
                        break;
                }
                break;
            case Constants.MESSAGE_WRITE:
                byte[] writeBuf = (byte[]) msg.obj;
                // construct a string from the buffer
                String writeMessage = new String(writeBuf);
                mConversationArrayAdapter.add("Me:  " + writeMessage);
                break;
            case Constants.MESSAGE_READ:
                byte[] readBuf = (byte[]) msg.obj;
                // construct a string from the valid bytes in the buffer
                String readMessage = new String(readBuf, 0, msg.arg1);
                mConversationArrayAdapter.add(mConnectedDeviceName + ":  " + readMessage);
                break;
            case Constants.MESSAGE_DEVICE_NAME:
                // save the connected device's name
                mConnectedDeviceName = msg.getData().getString(Constants.DEVICE_NAME);
                if (null != activity) {
                    Toast.makeText(activity, "Connected to "
                            + mConnectedDeviceName, Toast.LENGTH_SHORT).show();
                }
                break;
            case Constants.MESSAGE_TOAST:
                if (null != activity) {
                    Toast.makeText(activity, msg.getData().getString(Constants.TOAST),
                            Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
};

I have imported the Contents class: import android.provider.SyncStateContract.Constants;

BiKit avatar Mar 21 '19 18:03 BiKit

Have you been able to resolve the issue you encountered? If not might you be able to clarify?

  • The specific project that pertains to the issue (for example: the 'BluetoothLeGatt' project)
  • Steps to repro the issue, the API version and Android device model
  • If the issue is not about a sample, would you please file on Stackoverflow or the issue tracker and we will take a look there?
  • Please include code snippets as appropriate

isaidamier avatar Jun 25 '21 17:06 isaidamier