最近在寫關於Bluetooth的程式,希望以android的手機作為遙控器傳送字元指令來遙控東西,
但在寫藍牙程式遇到問題,我是參考這個網址http://developer.android.com/guide/topics/wireless/bluetooth.html
來寫藍牙程式但是我寫第一個程式
package irdc.blue;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.widget.Toast;
public class Blue extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Toast.makeText(this, "沒有提供藍芽通訊",Toast.LENGTH_LONG).show();
finish();
return;
}
if (!mBluetoothAdapter.isEnabled()){
Blue enableIntent = new Blue(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
}
就錯誤了~"~
他說Syntex error on token ";", (expected after this token
後面還有許多錯誤
The constructor Blue(String)is undefined
REQUEST_ENABLE_BT cannot be resolved to a variable
一直找不到到底是哪邊錯誤,有人能幫我解答嗎~"~
我要做的程式是需要按下按鈕"連結藍牙配對",然後按按鈕傳送指令去遙控 有人能幫我解決這樣子的程式嗎~"~
弄了好久也爬 好多文但是沒找到該如何 寫這程式
麻煩懂的大大能幫我解答感謝了><
1 則回應
那個值,自己定義就好,例如:
private static final int REQUEST_ENABLE_BT = 2;
在intent回call的時候,會丟回來給你,你可以藉此來知道回call的原由
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_ENABLE_BT)
{ if(resultCode == RESULT_OK)
}
}
實際上,你可以參考sdk下sample裡的bluechat,它也是自己定義的,很多書的範例名字跟它一模一樣。