2011-07-26 11 views
0

私は、チップからAndroidの携帯電話にデータを転送するBluetooth機能を使用するアンドロイドアプリケーションを開発しようとしています。私はコードを開発者のウェブサイト上のチュートリアルから変更していません。チップからBluetooth経由でデータを転送するにはどうすればよいですか?

私は、次のエラーを取得しています:ここで

_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 context = YourMainActivity.thisを実行し、それを使用する必要があります – Suchi

+0

私はあなたが答えることができるかどうか疑問に思っていたいくつかのより多くの質問がありますか? – YoKaGe

関連する問題