java - Stop conversion decimal to ascii -


i trying send int arduino android via bluetooth if send lets 56, receive 8 in android side...is there anyway can receive 56 , preferably in string form including characters

arduino code :

int level = 56; serial.write(level); 

android code :

 public void run() {         byte[] buffer = new byte[128];         int bytes;           while (true) {             try {                 bytes = connectedinputstream.read(buffer);                 string strreceived = new string(buffer, 0,bytes);                 final string msgreceived =/* string.valueof(bytes) +                         " bytes received: "                         + */strreceived;                    runonuithread(new runnable(){                      @override                     public void run() {                       textstatus.settext(msgreceived);                         value = msgreceived ;                     }}); 

value defined static string class variable

you're converting bytes string , therefore you're getting '8' (char)56;. if don't want that, follows.

bytes = connectedinputstream.read(buffer); string tmp = ""; for(int i=0;i<bytes;i++)     tmp += byte.tostring(buffer[i]);   final string msgreceived = tmp; 

edit

if send follows, example.

serial.write(56); serial.write(76);   

what receive in msgreceived 5676 if both these bytes read. can change behavior in whichever way want.


Comments

Popular posts from this blog

How to start daemon on android by adb -

testing - Detect whether test has failed within fixture -

Angularjs unit testing - ng-disabled not working when adding text to textarea -