2012-03-20 101 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 等

所有的代码是在你的系统只有你只能创建新的项目和新项目的代码复制执行该项目。