2011-07-26 49 views
0

我想開發一個Android應用程序,它將使用藍牙功能將數據從芯片傳輸到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