Android bluetooth SDP无法识别JAVAME中广告的服务
我正在为我的MSc开发蓝牙应用程序。结束项目。它包括一个用Android bluetooth SDP无法识别JAVAME中广告的服务,android,service,java-me,bluetooth,Android,Service,Java Me,Bluetooth,我正在为我的MSc开发蓝牙应用程序。结束项目。它包括一个用javame实现的服务器和一个用Android编写的客户端 问题是AndroidSDP似乎无法识别我的JavaME服务器的ServiceRecord 如果我在客户端中使用BluetoothDevice.getUuids()和BluetoothDevice.fetchUuidsWithSdp()方法,它们会返回一组UUID,但我的服务的UUID不在其中,因此我无法连接到它 这是JAVAME服务器示例的代码: /*IMPORTS*/ pub
javame
实现的服务器和一个用Android
编写的客户端
问题是AndroidSDP
似乎无法识别我的JavaME服务器的ServiceRecord
如果我在客户端中使用BluetoothDevice.getUuids()
和BluetoothDevice.fetchUuidsWithSdp()
方法,它们会返回一组UUID
,但我的服务的UUID
不在其中,因此我无法连接到它
这是JAVAME
服务器示例的代码:
/*IMPORTS*/
public class StackOverFlowServer extends MIDlet {
Display mDisplay;
Form mForm;
LocalDevice local;
StreamConnectionNotifier server;
ServiceRecord sr;
String conURL;
StreamConnection conn;
public StackOverFlowServer() {
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mForm);
mForm = new Form(null);
conURL = "btspp://localhost:68EE141812D211D78EED00B0D03D76EC;"
+ "authenticate=false;encrypt=false;name=MySampleApp";
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
try {
local = LocalDevice.getLocalDevice();
} catch (BluetoothStateException e) {
// Error handling code here
}
/*
* When creating a StreamConnectionNotifier a service record
* will automatically be created for us, describing the new
* service. The service will have the Serial Port (0x1101)
* value in the ServiceClassIDList (id 0x0001) attribute. The
* service record will also have both the L2CAP (0x0100) and
* RFCOMM (0x0003) values in the ProtocolDescriptorList (id
* 0x0004) attribute. Other mandatory attributes will be set
* automatically by the JABWT implementation. The optional
* ServiceName (id 0x100) attribute will be set to the name
* parameter, "BTDemoApp" in this case.
*/
try {
server = (StreamConnectionNotifier)
Connector.open(conURL);
} catch (IOException e1) {
// Error handling code here
}
/*
* The automatically created service record can be obtained
* from the LocalDevice object, using the reference to the
* StreamConnectionNotifier.
*/
try {
sr = local.getRecord(server);
}
catch (IllegalArgumentException iae){
// Error handling code here
}
/*
* We create a new DataElement and set its content correctly.
*/
DataElement elm = null;
/*
* Setting public browse root in the browsegrouplist
* attribute. The BrowseGroupList (id 0x0005) attribute
* contains a DataElement sequence, which in turn contains
* DataElements with UUIDs. The DataElement sequence must be
* created before we can add DataElements to it.
*/
elm = new DataElement(DataElement.DATSEQ);
elm.addElement(new DataElement(
DataElement.UUID,new UUID(0x1002)));
/*
* The DataElement is now prepared. It must be added to the
* appropriate attribute ID, in this case the
* BrowseGroupList.
*/
sr.setAttributeValue(0x0005,elm);
/*
* Finally, the service record must be updated in our
* LocalDevice.
*/
try {
local.updateRecord(sr);
} catch (ServiceRegistrationException e3) {
// Error handling code here
}
try {
conn = server.acceptAndOpen();
} catch (ServiceRegistrationException sre){
// Error handling code here
} catch (IOException e2) {
// Error handling code here
}
/*
* At this point a client is connected. input and output
* streams can be obtained from the conn object,
* communication can begin.
*/
}
}
这是Android客户端的一部分:
package com.exampleproyect.stackoverflowclient;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.os.Parcelable;
public class StackOverFlowClientActivity extends Activity {
BluetoothAdapter mBluetoothAdapter;
BluetoothDevice C702;
BroadcastReceiver mReceiver;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
C702 = mBluetoothAdapter.getRemoteDevice("00:23:F1:27:16:DA");
C702.fetchUuidsWithSdp();
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_UUID.equals(action)){
Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
/*uuidExtra should contain my service's UUID among his files, but it doesn't!!*/
}
}
};
// Register the BroadcastReceiver
IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_UUID);
registerReceiver(mReceiver, filter1); // Don't forget to unregister during onDestroy
}
}
最让我困扰的是,我的计算机可以正确地看到我的JAVAME
服务器广告:
我做错了什么??:(为什么我的电脑的蓝牙可以在JAVAME
中正确地看到我的服务广告,而Android却不能?Android
可以通过蓝牙连接到JAVAME
服务器
我在StackOverFlow阅读了大量其他类似的问题,但我还没有找到有效的解决方案(
我正在使用索尼爱立信C702(Java平台8)作为测试服务器,以及三星Galaxy S(ICS4.0.3,团队ICSSGS RC4.2)
EDIT1 嗯 我知道问题是什么 我希望JAVAME服务器使用UUID(例如):“68EE1418-12D2-11D7-8EED-00B0D03D76EC”发布我的服务,但代码似乎是:
conURL = "btspp://localhost:68EE141812D211D78EED00B0D03D76EC;"
+ "authenticate=false;encrypt=false;name=MySampleApp";
server = (StreamConnectionNotifier)
Connector.open(conURL);
将默认串行端口服务UUID“00001101-0000-1000-8000-00805F9B34FB”添加为ServiceClassIDList atribute:
现在,有趣的是Android方法BluetoothDevice.FetchUUIDSWithDP();
似乎获取默认的“00001101-0000-1000-8000-00805F9B34FB”UUID,而不是我的“68EE1418-12D2-11D7-8EED-00B0D03D76EC”UUID,使我的服务与手机的默认串行端口服务重叠
类似于中世纪的蓝牙网络扫描仪,它可以识别我的服务,但广告名为“00001101-0000-1000-8000-00805F9B34FB”:
如何删除JAVAME
自动添加到我的服务中的额外UUID
请帮忙,谢谢
EDIT2
好的,问题是索尼爱立信的手机。显然,它们插入了标准串行端口UUID{0x1101}
在我定制的UUID
之前,而三星和诺基亚手机则在我自己的服务记录后面插入此标准UUID
。Android似乎只获取服务记录上属性0x001
的第一个值,因此将我的服务与某些设备附带的默认串行端口混淆
因此,解决方案将是:
除了ServiceClassID(0x001)
,当前的Android API还有什么方法可以获取更多的servicecord
属性吗
或
是否有任何方法可以更新服务发现数据库(SDDB)中存储在“AcceptEndOpen”之后的
servicerecord
-JAVAME-已被调用?-我使用了LocalDevice.updateRecord
在SDDB
上创建服务后,它在模拟器上工作,但出现异常,在实际设备上不做任何操作。找到解决方案了吗?我也有同样的问题