I am doing something with NXT and Android APP, but it is not easy.
I managed to connect an NXJ and an Android device, but no data was sent.
I am trying to send data from Android to NXT.
First I got the code for the Android app:
public void writeMessage(byte msg, String nxt) throws InterruptedException{ BluetoothSocket connSock; //Swith nxt socket if(nxt.equals("nxt1")){ connSock=socket_nxt1; }else{ connSock=null; Log.d("write","Err"); } if(connSock!=null){ try { OutputStreamWriter out = new OutputStreamWriter(connSock.getOutputStream()); out.write(msg); out.flush(); Thread.sleep(1000); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ //Error Log.d("write","Err"); } }
And this is for NXT:
while(true){ LCD.drawString(waiting,0,0); LCD.refresh(); BTConnection btc = Bluetooth.waitForConnection(); LCD.clear(); LCD.drawString(connected,0,0); LCD.refresh(); DataInputStream dis = btc.openDataInputStream(); DataOutputStream dos = btc.openDataOutputStream(); for(int i=0;i<1;i++) { byte n = dis.readByte(); LCD.drawInt(n,0,1); LCD.refresh(); dos.writeInt(-n); dos.flush(); } dis.close(); dos.close(); Thread.sleep(1000);
source share