Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java me netbeans bluetooth application sending a picture problem, it doesnt send the picture to the recieving phone but the phone is detected, when i send it, gives message error "dont find any record" it shows the other phone name emlname once i click send it lags for a while ant gives the error "dont find any record"

Java
//POSIBLE LOGIC ERRORS COULD BE IN THE FOLLOWING CODE
public void serviceSearchCompleted(int i, int i0) {
        String message = "";
        switch(i0){
            case DiscoveryListener.SERVICE_SEARCH_COMPLETED:
                //Inquiry is complete, start the client
                if(sr != null){
                    devices.setTitle("sending picture...");
                    handle = new ClientHandle();
                    return;
                }
              case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
               message = "don't find any record";
                break;
            default:
                break;
        }
        devices.setTitle("no service");
        Alert a = BTMIDlet.getAlert(message,AlertType.INFO,2000);
        Display.getDisplay(midlet).setCurrent(a);
 

 public void commandAction(Command command, Displayable displayable) {
        if(command.getCommandType() == Command.BACK){
            //Return
        }
        if(command == List.SELECT_COMMAND){
            int i = devices.getSelectedIndex();
            UUID[] uuids = new UUID[1];
            uuids[0] = new UUID(0x0001);
            try {
                //Query services on the specified device
                devices.setTitle("looking for services...");
                bt.getDiscoveryAgent().searchServices(null,uuids,(RemoteDevice)deviceVector.elementAt(i),this);
            } catch (BluetoothStateException ex) {
                ex.printStackTrace();
                showException(ex);
            }
        }
    }
 
 public void run(){
            //Connect to the server
            String url = sr.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,false);
            int i = url.indexOf(":");
            String protocol = url.substring(0,i);
            //According to different protocols, different ways to send data
            if(protocol.equals("btspp")){
                StreamConnection conn = null;
                try {
                    //Stream connection to send a relatively simple
                    conn = (StreamConnection)Connector.open(url);
                    OutputStream os = conn.openOutputStream();
                    os.write(midlet.getImage());
                    os.flush();
                    os.close();
                    conn.close();
                    
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }else if(protocol.equals("btl2cap")){
                L2CAPConnection conn = null;
                try{
                    conn = (L2CAPConnection)Connector.open(url);
                    //L2CAPConnection Is a connection-oriented, need to consider MTU
                    int max = conn.getTransmitMTU();
                    byte[] img = midlet.getImage();
                    byte[] buffer = new byte[max];
                    int index = 0;
                    //Each time you send a data buffer, and no more than MTU
                    while(index <img.length){
                        //Length less than max, you need to send the interception of part of the
                        if(img.length - index<max){>
                            buffer = new byte[img.length-index];
                            System.arraycopy(img,index,buffer,0,img.length-index);
                        }else{
                            System.arraycopy(img,index,buffer,0,max);
                        }
                        conn.send(buffer);
                        index+=max;
                    }
                   conn.close();
                } catch (Exception ex) {
                    showException(ex);
                }
            }
        }
    }
}
Posted
Updated 30-Nov-11 8:27am
v6
Comments
OriginalGriff 30-Nov-11 12:09pm    
That is called a code dump - and it is pointless and rude. Post only the relevant fragments so we don't have to search through scads of irrelevant code to find the problem.
And put a brief summary in the subject, and the question in the body! I have moved it, but it was truncated when you posted it.
Use the "Improve question" widget to edit your question and provide better information.
Nagy Vilmos 30-Nov-11 12:12pm    
What is the COMPLETE error when you try it?
RealRevendell 30-Nov-11 12:35pm    
This error message apears
case DiscoveryListener.SERVICE_SEARCH_NO_RECORDS:
message = "don't find any record";
Give me a moment to improve my question as i cant expect you guys to read all of it
RealRevendell 30-Nov-11 12:59pm    
Sorry guys i just added a comment that it should be in the server class cuz my reason is that the phone takes a pic and finds the other phone but doesnt send the pic :-0 tnx for the help guys realy apreciate it im a newbew....
Richard MacCutchan 30-Nov-11 13:18pm    
First thing you need to do is remove all the code not relevant to the question and put the proper formatting back; just look at it now, it's totally unreadable!

The second thing is to explain at exactly what point it is going wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900