2011-07-26 5 views
0

칩에서 Android 폰으로 데이터를 전송하는 Bluetooth 기능을 사용하는 Android 애플리케이션을 개발하려고합니다. 개발자 웹 사이트의 튜토리얼 코드를 전혀 변경하지 않았습니다. 여기 블루투스를 통해 칩에서 데이터를 전송하려면 어떻게해야합니까?

_context cannot be resolved as a variable 

내 코드입니다 :

나는 다음과 같은 오류를 얻고있다

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(_context); 
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
    if (mBluetoothAdapter == null) {  
     // Device does not support Bluetooth   
    } 
    if (!mBluetoothAdapter.isEnabled()) {  
     Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);  
     startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); 
    } 
} 

답변

0

사용

LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(this); 

또는

Context context = this; 
LocalBluetoothDevice localBT = LocalBluetoothDevice.initLocalDevice(context); 
+0

W 암탉이 시도했다 initLocalDevice 형식의 LocalBluetoothDevice – YoKaGe

+2

프로젝트의 주요 활동에 대한 정의되지 않은 오류와 함께 나온? 컨텍스트 context = YourMainActivity.this를 수행 한 다음 사용하십시오. – Suchi

+0

대답 할 수 있다면 궁금한 몇 가지 질문이 생깁니다. – YoKaGe

관련 문제