java - Input editText as hex, send as int? -
I send data from your Android app for a Bluetooth module using the SPP with the following method, which takes an integer I am
enter the public zero heck (int i) {try {mmOutStream.write (i); } Catch (IOException e) {}}
When I do it uses with an integer like '0xD' I do not work properly, so there is nothing wrong. However, I am trying to get data from an editing text that is formatted so that it can accept as a 0-F input only. From here I thought. I will need to convert to add '0x' string and then int
For example entered my editText '4E', I have a new string builder '0x' To begin with is to create. I then add the value of my 4E to the string and convert the int. Although I get an error when he is trying to change int, this is invalid.
I know that this is probably so wrong, but I have no better idea about how to do this? Any answer or signal will be DEB highly appreciated. Below is my code for conversions:
btnSendHex.setOnClickListener (New OnClickListener () {public void onClick (View v) {StringBuilder hexString = new StringBuilder (); hexString.append ( "0x "); hexString.append (dataInputHex.getText () toString ()) ;. string hexWrite = hexString.toString (); int hexValue = Integer.parseInt (hexWrite); mConnectedThread.writeHex (hexValue);}});
thanks
Comments
Post a Comment