2012-03-20 92 views
0

我的Android3.0關於藍牙聊天應用

http://developer.android.com/resources/samples/BluetoothChat/res/index.html執行此示例代碼

藍牙聊天

<!-- BluetoothChat --> 
<string name="send">Send</string> 
<string name="not_connected">You are not connected to a device</string> 
<string name="bt_not_enabled_leaving">Bluetooth was not enabled. Leaving Bluetooth Chat.</string> 
<string name="title_connecting">connecting...</string> 
<string name="title_connected_to">connected to <xliff:g id="device_name">%1$s</xliff:g></string> 
<string name="title_not_connected">not connected</string> 

<!-- DeviceListActivity --> 
<string name="scanning">scanning for devices...</string> 
<string name="select_device">select a device to connect</string> 
<string name="none_paired">No devices have been paired</string> 
<string name="none_found">No devices found</string> 
<string name="title_paired_devices">Paired Devices</string> 
<string name="title_other_devices">Other Available Devices</string> 
<string name="button_scan">Scan for devices</string> 

<!-- Options Menu --> 
<string name="secure_connect">Connect a device - Secure</string> 
<string name="insecure_connect">Connect a device - Insecure</string> 
<string name="discoverable">Make discoverable</string> 

如果我AVD管理設置爲2.2它給我有些錯誤..

爲什麼?

+1

有些錯誤?不是其他錯誤? – 2012-03-20 02:57:10

+1

你怎麼樣設法利用BT與模擬器.... – 2012-03-20 03:16:48

+0

你說,你曾用「在Android3.0的示例代碼」來創建一個項目,改變其目標至Android 2.2及項目開始出現的錯誤..這可能是因爲android3.0示例可能已經使用了一些在android 2.2中不可用的函數。如果您需要創建項目針對的Android2.2然後使用Android2.2的示例代碼,而不是3.0 – 2012-03-20 04:59:42

回答

1

好吧..聽起來像你有SDK3.x和以上只有在你的bluetoothChat應用程序的功能。首先,操作欄是Android 3+功能。在這種情況下,你將有一個問題,回到目標Android v2.2

我的示例應用程序的副本來自2.1的例子,它適用於SDK 2.1(玩這個最多)和2.2(只是改變爲此),我找不到任何它在我的任何java文件中使用listenUsingInsecureRfcommWithServiceRecord()。

嘗試使用SDK經理搶SDK 2.2的樣本,並從那裏重新導入,看看你是否有同樣的問題。

+0

好的,我會試試。謝謝 – Venkat 2012-03-20 05:13:08

+0

不客氣!我希望它有幫助。讓我知道如果沒有,這裏就不會有其他事情了 - 我已經全部通過這個應用程序。 – 2012-03-20 22:08:20

+0

所以...我的回答對你有幫助嗎?在這種情況下,你可以接受答案。謝謝。 – 2012-03-22 05:44:54

0

這個程序實際上會拒絕運行和關閉自行關閉(顯示吐司),如果你在模擬器上運行它。

它檢查做任何事情之前藍牙無線電,和仿真器沒有一個。

檢查該片段從BluetoothChbat.java - 在BluetoothChat活動的onCreate功能。

// Get local Bluetooth adapter 
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

    // If the adapter is null, then Bluetooth is not supported 
    if (mBluetoothAdapter == null) { 
     Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); 
     finish(); 
     return; 
    } 
+0

適用於任何應用bluetoothchat {我知道,我的問題是什麼之後形成的項目,如果我改變Android屬性爲android 2.2,那麼整個項目就會出錯。} – Venkat 2012-03-20 04:19:20

+0

快速確認:你的意思是你正在改變AVD運行2.2操作系統或更改你的目標爲2.2的SDK?無論哪一個,之前是什麼,並且之前是否奏效?請對你的問題更精確一點。我已經花了相當一段時間與這個應用程序,並沒有任何奇怪的問題,這並不是由我自己的編碼更改造成的.... – 2012-03-20 04:37:11

+0

如果我將標準的Android平臺3.0更改爲2.2該項目獲取錯誤。 – Venkat 2012-03-20 04:40:14

1

爲Android 2.2也是一個樣本bluetoothchat應用程序有沒有在你的SDK文件夾 Android的sdk_r11-WINDOWS \ Android的SDK-WINDOWS \樣本\ Android的7 Android的sdk_r11-WINDOWS \ Android的SDK-WINDOWS \樣本\ Android的8 Android的sdk_r11-WINDOWS \ Android的SDK-WINDOWS \樣本\ Android的9 等

所有的代碼是在你的系統只有你只能創建新的項目和新項目的代碼複製執行該項目。