누구든지 파일이나 메시지를 한 쪽 끝에서 다른 쪽 끝까지 전송할 수있는 블루투스 서버 클라이언트 (안드로이드에서 컴퓨터로)의 작동 예제를 줄 수 있습니까? TCP로 만들지 만, 지난 2 일 동안 블루투스로 성공했습니다.
Google에서 일부 기사를 찾았지만 성공할 수 없습니다. This 튜토리얼에서 직접 시도했지만 onResume()에 예외가 발생했습니다.
내 안드로이드 모바일에서 내 PC로 데이터를 전송하고 싶습니다. 실행중인 윈도우 7. 지금은 제대로 작동하는 코드를 사용합니다. 왜냐하면 logcat에서 연결이 성공적으로 설정되고 데이터가 완벽하게 읽혀지기 때문입니다. 내 컴퓨터로 데이터를 전송하지 않습니다 (해당 데이터를 쓸 수 없음).
내 질문에 뭔가가 없거나 서버 코드와 같은 코드가 필요합니까? 아니면 누군가가 성공적으로 코드 일부를 제안 할 수 있습니까? 메시지 또는 파일을 클라이언트 안드로이드에서 서버 PC으로 전송할 수 있습니까?
MY 코드 :블루투스를 통해 안드로이드에서 PC로 데이터 전송하기
Button btnSend = null;
TextView txtPath = null;
Socket s = null;
BluetoothAdapter objBluetoothAdapter = null;
BluetoothDevice device = null;
BluetoothSocket socket = null;
String strPath = "/sdcard/bluetooth/IMG0245A.jpg";
byte [] buffer = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSend = (Button)findViewById(R.id.send_button);
btnSend.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String address="MY_COMPUTER_BLUETOOTH_ADDRESS";
objBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(objBluetoothAdapter==null){
Toast.makeText(this, "BT not supported", Toast.LENGTH_LONG);
return;
}
//objBluetoothAdapter.enable();
if(!objBluetoothAdapter.isEnabled()){
Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBT);
}
try{
device = objBluetoothAdapter.getRemoteDevice(address);
final UUID uuid= UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try{
File f = new File(strPath);
buffer = new byte[(int)f.length()];
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(buffer,0,(int)f.length());
socket = device.createRfcommSocketToServiceRecord(uuid);
Log.d("BT","RF Connection Created"+socket);
//objBluetoothAdapter.startDiscovery();
for(int i=0;i<3;i++){
try{
objBluetoothAdapter.cancelDiscovery();
socket.connect();
Log.d("BT","Socket Connected = "+socket);
break;
}catch (Exception e) {
// TODO: handle exception
Log.d("BT","Socket Connection exception = "+e);
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.d("BT","Connection NOT OK");
}
OutputStream os = socket.getOutputStream();
os.write(buffer);//,0,buffer.length);
os.flush();
os.close();
socket.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this,"exception "+e, Toast.LENGTH_LONG);
}
}
다음을 확인하십시오. http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html 나는 그것을 스스로 사용했으며 잘 작동합니다. –