在尝试实施一个简单的广告应用程序时,我设法启动广告流程,但是当我尝试停止广告时,我收到一个整数值为4的错误。附加的是在停止广告时调用的advertiseStopCallBack的实现。 似乎使用两种不同的回调方法进行启动/停止广告会产生错误,有人可以解释原因吗?
private AdvertiseCallback advertiseStopCallback = new AdvertiseCallback() {
@Override
public void onSuccess(AdvertiseSettings advertiseSettings) {
String successMsg = "Advertisement stop command attempt successful";
Log.d(TAG, successMsg);
}
@Override
public void onFailure(int i) {
String failMsg = "Advertisement stop command attempt failed: " + i;
Log.e(TAG, failMsg);
}
};
private AdvertiseCallback advertiseStopCallback = new AdvertiseCallback() {
@Override
public void onSuccess(AdvertiseSettings advertiseSettings) {
String successMsg = "Advertisement stop command attempt successful";
Log.d(TAG, successMsg);
}
@Override
public void onFailure(int i) {
String failMsg = "Advertisement stop command attempt failed: " + i;
Log.e(TAG, failMsg);
}
};
答案 0 :(得分:1)
从Android L SDK引用中,值为4的错误是:
ADVERTISE_FAILED_NOT_STARTED
其含义是:
ADVERTISE_FAILED_NOT_STARTED
由于广告未启动,因此无法停止投放广告。
常数值:4(0x00000004)
当BluetoothAdvertiser开始宣传数据时(两种启动方式)应设置回调对象,并且当调用stopAdvertising()时,它将删除BluetoothAdvertiser与相应回调对象之间的(Observer)关系。如果使用callback1启动广告(),使用callback2启动stopAdvertising(),系统发现callback2与此BluetoothAdvertiser对象无关,则会导致ADVERTISE_FAILED_NOT_STARTED失败。
实际上,您可以为单个BluetoothAdvertiser设置多个回调,并确保在禁用广告功能时停止所有回调。