Visualizzazione stampabile
-
Bluetooth File Trasfert
Salve a tutti mi sono da poco iscritto su questo bellissimo sito, dove ho trovato tantissime soluzioni per i miei problemi di programmazione.
La mia applicazione consiste in un registratore audio a salvare il file nella sd-card, inoltre posso visualizzare in una nuova activity la lista delle registrazione effettuate e selezionare quale si vuole condividere.La condivisione deve avvenire attraverso il bluetooth, il mio problema è di non comprendere bene come effettuare una comunicazione, comunque ho preso spunto dal BluetoothChat del sito android,ma il problema è che io devo inviare file audio e non stringhe di testo come avviene per il BluetoothChat e quindi non so come implementarla per il mio utilizzo.Mi sapete dare dei consigli?
GRAZIE A TUTTI
-
Nessuno mi può aiutare.Ho delle novità sono riuscito ad inviare il file audio mettendo nel sendMessage in BluetoothChat tramite questo codice
Quote:
File file = new File(nome+"."+formato);
InputStream in = null;
try {
try {
in = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[(int) file.length()];
String n=""+buffer.length;
Toast.makeText(getApplicationContext(),n, Toast.LENGTH_LONG).show();
in.read(buffer, 0, (int) file.length());// salva nel buffer il file
mChatService.write(buffer);// passo al metodo i byte del mio file
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
in ricezione leggo dal socket con questo codice in BluetoothChatService
Quote:
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread: ");
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
// Get the BluetoothSocket input and output streams
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
IL problema è sul fatto che il vettore di byte è di 1024 ma io invio file audio e non mi bastano e anche se aumento il valore posso arrivare ad un valore in byte circa 2500.
MI potete dare una mano?