Results 1 to 6 of 6
  1. #1
    Ashuk is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Can anyone explain me what happens here for the byte array

    If anyone could explain me what happens to the incoming byte array would be a great help. Thanks

    `
    Java Code:
    case BT_MESSAGE_WRITE:
                 byte[] writeBuf = (byte[]) msg.obj;
             // construct a string from the buffer
                 String writeMessage = new String(writeBuf);
                 mConversationArrayAdapter.add("Me:  " + writeMessage);
                break;
    
    
        case BT_MESSAGE_READ:
                 byte[] readBuf = (byte[]) msg.obj;
    
                 ImageFileService.SaveImagetoSD(readBuf, msg.arg1);
                // construct a string from the valid bytes in the buffer
                String readMessage = new String(readBuf, 0, msg.arg1);
                 //if(D) Log.d(BTTAG, " readMessage = " + readMessage + "; " +
                 //msg.arg1 + " bytes.");
    
                DisplayImage();

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Can anyone explain me what happens here for the byte array

    what line(s) of code are you asking about? What problems are you having?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Ashuk is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Re: Can anyone explain me what happens here for the byte array

    byte[] writeBuf = (byte[]) msg.obj; and byte[] readBuf = (byte[]) msg.obj;

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Can anyone explain me what happens here for the byte array

    Those statements cast the value in msg.obj to a byte[] and assign it to a variable.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Ashuk is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Re: Can anyone explain me what happens here for the byte array

    Quote Originally Posted by Norm View Post
    Those statements cast the value in msg.obj to a byte[] and assign it to a variable.
    Thanks bro, and can you say me what this means "String readMessage = new String(readBuf, 0, msg.arg1);" im sorry for troubling you since im new to java.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Can anyone explain me what happens here for the byte array

    Read the API doc for the String class to see how to use its constructors.
    http://docs.oracle.com/javase/7/docs/api/
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 01-11-2013, 06:52 AM
  2. Please explain to me this array
    By Mercy in forum New To Java
    Replies: 6
    Last Post: 11-30-2012, 12:42 AM
  3. Replies: 1
    Last Post: 10-21-2011, 11:55 AM
  4. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  5. Replies: 3
    Last Post: 09-06-2010, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •