2012-03-07 3 views
0

내 응용 프로그램 : /** * 블루투스 smarphone를 연결하십시오. * 블루투스 버튼에 자동으로 블루투스를 해제 */안드로이드에 Arduino 블루투스

package com.Iris; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 
import android.bluetooth.BluetoothAdapter; 
import android.bluetooth.BluetoothDevice; 
import java.util.Set; 




public class IrisActivity extends Activity 
{ 
Button button1; 
// button Off bluettooch 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
button1 = (Button) findViewById(R.id.button1); 
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
// ac 
bluetoothAdapter.enable(); 

Toast.makeText(IrisActivity.this, "Bluetooth Activé", Toast.LENGTH_SHORT).show(); 

Set<BluetoothDevice> devices; 
devices = bluetoothAdapter.getBondedDevices(); 
for (BluetoothDevice blueDevice : devices) 
{ 
Toast.makeText(IrisActivity.this, "Réseau : " + blueDevice.getName(), Toast.LENGTH_SHORT).show(); 
} 


button1.setOnClickListener(new View.OnClickListener() 
{ 
public void onClick(View v) 
{ 
bluetoothAdapter.disable(); 
Toast.makeText(IrisActivity.this, "Bluetooth Désactivé", Toast.LENGTH_SHORT).show(); 
} 
}); 

} 

내 응용 프로그램이 좋은,하지만 난 "blueDevice.getName"에 연결하고 내 응용 프로그램과 함께 ASCI 문자 "H"를 보내 원하는

수 너 나 도와?

답변

0

BluetoothChat 샘플을 살펴보십시오. 기본적으로, 당신은 송신 측에서 다음을 수행해야합니다 :

BluetoothSocket socket = blueDevice.connect(); 
OutputStream os = socket.getOutputStream(); 
os.write("H"); 

당신은 샘플에 표시된 수신 측에 서버 소켓을해야합니다.

+0

감사합니다. 그렇다면이 코드를 어디에서 코드에 포함할까요? 감사 – user1255077

관련 문제