Oggi ho provato a fare così:
SENDER:
invio_byte_foto=new Thread(){
public void run(){
SharedPreferences prefs=getSharedPreferences(TabProfileActivity.PROFILO_UTENTE,Context.MODE_PRIVATE);
String uri_photo=prefs.getString("photo", "");
Uri picturez = Uri.parse(uri_photo);
Bitmap fotoBitmap = null;
try {
fotoBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), picturez);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e("ERRORE", "ERRORE NEL CARICARE LA FOTO",e);
return;
}
boolean valrest=fotoBitmap.compress(Bitmap.CompressFormat.JPEG, 100, mmOutStream);
Log.i("VALORE RESTITUITO DA BITMAP COMPRESS", ""+valrest);
Log.i("Scambio Profili Completi", "Termine invio Foto");
}
};
invio_byte_foto.start();RECIVER:
ricevi_byte_foto=new Thread(){
public void run(){
Log.i("Scambio Profili Completi", "Inizio Ricezione Foto");
try{
Bitmap bitmapimage=BitmapFactory.decodeStream(mmInStream);
String filename = "foto"+device.getAddress()+".jpg";
File imagefile = new File(Environment.getExternalStorageDirectory() ,filename);
imagefile.mkdir();
FileOutputStream fos = new FileOutputStream(imagefile);
bitmapimage.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
//ricavare dal bitmap l'uri che salverò nel infoProfilo
Uri foto=Uri.fromFile(new File(filename));
info_profilo_utente.setUri_string_foto(foto.toString());
Log.i("Scambio Profili Completi", "Fine Ricezione Foto");
}catch (Exception e) {
Log.e("ERRORE", "Exception during read photo", e);
return;
}
}
};
ricevi_byte_foto.start();Però mi dà il seguente errore:
01-22 17:04:47.696: W/System.err(3116): java.io.IOException: Operation Canceled
01-22 17:04:47.696: W/System.err(3116): at android.bluetooth.BluetoothSocket.readNative(Native Method)
01-22 17:04:47.696: W/System.err(3116): at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:307)
01-22 17:04:47.706: W/System.err(3116): at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
01-22 17:04:47.706: W/System.err(3116): at java.io.InputStream.read(InputStream.java:133)
01-22 17:04:47.706: W/System.err(3116): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:157)
01-22 17:04:47.706: W/System.err(3116): at java.io.BufferedInputStream.read(BufferedInputStream.java:346)
01-22 17:04:47.706: W/System.err(3116): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-22 17:04:47.706: W/System.err(3116): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
01-22 17:04:47.706: W/System.err(3116): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
01-22 17:04:47.706: W/System.err(3116): at griglie.progetto.CercaPersoneService$ConnectedThread$4.run(CercaPersoneService.java:593)
01-22 17:04:47.706: D/skia(3116): ---- read threw an exception
01-22 17:04:47.716: D/skia(3116): --- decoder->decode returned false
Non sò più dove mettere le mani!!! E come se mi chiudesse il socket!!