Thursday, March 14, 2013

Re: [android-developers] bluetooth file transfer failure

Indicator Veritatis wrote:
In order to answer your question, we need to see the code where you create and set mmInstream, too. For all we know, you might have forgotten to connect it to any stream,

Follow this advice:
http://sscce.org/
 

 akash roy wrote:
here  i am trying to send a file over bluetooth but its not sending any data.
here the main problem is that its not sending or receiving any data over the two devices but they are connected to each other.

<on configuring the bluetooth chat example.>


Sending code:


     File myFile = new File(message.toURI());

Are you quite certain 'message' translates properly to a URI that the 'File' constructor can use?

Are you certain that the abstract pathname represented by the 'File' instance is accessible?

 
     Double nosofpackets = Math.ceil(((int) myFile.length() )/4096);

'Math.ceil()' makes no sense with integer expressions. It will only return the argument's value.

Are you quite certain that the length of the file will fit in an 'int'?

Why does 'nosofpackets' (a non-compliant name) have to be 'Double' rather than 'double'?

     System.out.println(nosofpackets);
     BufferedInputStream bis= new BufferedInputStream(new FileInputStream(myFile));
     byte[] send = new byte[4096];
     for(double i=0; i<nosofpackets; i++)

'int' would be a better type for a loop index. It's actually pretty strange to think about what 
a 'double' is doing here.
 
     {
          send = null ;

So why do you null out this variable and forget and eventually de-allocate the array?
 
          a=bis.read(send, 0,send.length);

NPE!

You can't get the length of 'null'.

You did not tell us you were getting exceptions. How come?

What is 'a'?

 
          Log.d("BluetoothChat", "data packet " + i);
          if(a==-1)
          {
              break;
          }
          mChatService.write(send);
     }


Receiving code :


    while((bytes = mmInStream.read(buffer))>0)

What are these variables?
 
    {
    
    Log.d(TAG, "data is there for writing");
    bos.write(buffer);
    
    }

Incomplete question, cannot be answered completely.

-- 
Lew

--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate