[android-developers] [Android4.2.2] Bluetooth Opp transfer can't work nornally

2013-06-18 Thread weixiang
Hi

There is a problem bothering me recently, when my phone version updated to 
4.2.2. I found there are changed as to Bluetooth Module. BT stack changed 
from bluez to bluedroid.

and i writed a simple apk to tets Bt opp file transfer. but result is 
failed. now. i paste some pieces of code and logcat ,  hope someone to hele 
me or give some suggestion.

code : 

ContentValues values =

*new* ContentValues(); 

values.put(BluetoothShare.

*URI*, Uri.*parse*(file:///storage/sdcard1/Test.mp3).toString()); 

values.put(BluetoothShare.*DESTINATION*, mydevice.getAddress());

values.put(BluetoothShare.*MIMETYPE*, */*);

values.put(BluetoothShare.*FILENAME_HINT*, Opp_Test.mp3); 

values.put(BluetoothShare.*DIRECTION*, BluetoothShare.*DIRECTION_OUTBOUND*);

Long ts = System.*currentTimeMillis*();

values.put(BluetoothShare.TIMESTAMP,ts);

Uri contentUri=myContext.getContentResolver().insert(BluetoothShare.*
CONTENT_URI*, values);
logcat:
D/BtOppService( 1316): insertShare parsed URI: 
file:///storage/sdcard1/Test.mp3
D/BluetoothOppUtility( 1316): getSendFileInfo: 
uri=file:///storage/sdcard1/Opp_Test.mp3
E/BtOppService( 1316): Can't open file for OUTBOUND info 91 ---Failed
D/BluetoothOppUtility( 1316): closeSendFileInfo: 
uri=file:///storage/sdcard1/Opp_Test.mp3
 
then I go 2  BtOppService this java file to check, find this exception is 
caused by 
catch (FileNotFoundException e) {
Log.e(TAG, Can't open file for OUTBOUND info  + 
info.mId);
}
but this File exists in external SD card , and i add permission to access 
it.
 
BTW ,this method is workabled in andorid ICS/JB 4.1 
 
any one can help me?
 

-- 
-- 
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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[android-developers] 【Android】bluetooth file transfer

2012-06-18 Thread weixiang
hello,I am Tester using InstrumetationTestCase to Test, and i want to write 
some case about file transfer,However,when run,logcat display  some abnormal
below is my code,debug process,  the defect pointer is 
  while(bis.read() != -1)
{ 
if(bis.read(mybytearray) == -1) break;

for(int i = 0 ; i  mybytearray.length ; i++)
{ 
Log.e(weixiang --!!!,start Write);
outStream.write(mybytearray[i]);
} 

}
but I don't know how to fixed it~
 
***
public void testBTFileTransfer() throws Exception {
BluetoothDevice 
remotebtdevice=mybluetooth.getRemoteDevice(searchBtDeviceMAC_pcsuit);
String sdcard=Environment.getExternalStorageDirectory()+/;
//String filepath= sdcard + Wifi_Module_Test/+1.mp3;
String filepath= sdcard + Wifi_Module_Test/+1.mp3;
Log.e(# weixiang Tag ###, filepath);
if(remotebtdevice.getBondState() != BluetoothDevice.BOND_BONDED)
{
testBTPairresult_accept();
}
  new FileTransferThread(remotebtdevice).start();
sleep(300*1000);  
}
private class FileTransferThread extends Thread
{
private final BluetoothDevice mydevice;
private final BluetoothSocket mysocket;
//static final String SPP_UUID = 1106--1000-8000-00805F9B34FB;
static final String SPP_UUID =1105--1000-8000-00805f9b34fb;

//private final OutputStream outStream;
private final UUID uuid;
private  InputStream mmInStream;   
private  OutputStream mmOutStream;
public FileTransferThread(BluetoothDevice device) throws IOException{
mydevice=device;
BluetoothSocket temsocket=null;
uuid= UUID.fromString(SPP_UUID);
//InputStream tmpIn = null;
//OutputStream tmpOut = null;
try{

temsocket=device.createRfcommSocketToServiceRecord(uuid);

}catch (IOException e){}
mysocket=temsocket;
}


public void run()
{

// add new socket Access
try {
mysocket.connect();
} catch (IOException connectException) {

try{
mysocket.close();
} catch(IOException closeException) {}
// TODO Auto-generated catch block
}

 //below is for Read/Write stream
 File myfile=new File(filepath);
 byte[] mybytearray = new byte[(int)myfile.length()]; 
 Log.e(TAG,file length() = + (int)myfile.length());
 OutputStream outStream = null;
 FileInputStream fis = null;
 
 
 //init outputstream
 try{
 outStream =mysocket.getOutputStream();
 Log.e(tag1, outputstream create success);
 }catch (IOException e)
 {
 Log.e(tag1, ON RESUME: Output stream creation failed.);
 }
 
 //init inputstream
try {
fis = new FileInputStream(myfile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}   


 Log.e(TAG,fis created);
 
 BufferedInputStream bis = new BufferedInputStream(fis,4*1024 ); 
 Log.e(TAG,bis created success); 
 
 /*
 try {
bis.read(mybytearray,0,mybytearray.length);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/


 
 try {

 
 while(bis.read() != -1)
 {  
 if(bis.read(mybytearray) == -1) break;
 
 for(int i = 0 ; i  mybytearray.length ; i++)
 {
 Log.e(weixiang   --!!!,start Write);
 outStream.write(mybytearray[i]);
 } 
 
 }
 //Log.e(weixiang   --!!!,read over!!!);

 /*
 while(bis.read()!= -1)
 {
 outStream.write(mybytearray, 0, mybytearray.length);
 Log.e(weixiang   --!!!,start Write);
 }
 /*
 for(int i = 0 ; i  mybytearray.length ; i++){ } 
 */
 
 
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
 Log.d(TAG,BYTES WRITTEN to OUTSTREAM of socket);   
 try {
outStream.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} Log.d(TAG,bytes flushed); 
 try {
outStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 try {
mysocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 Log.d(TAG,socket closed);  
 
 
} 
}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post