我正在学习如何在Android上使用蓝牙,我为//main.qml
Rectangle{
id: root
property point dragStart
signal moved(point offset)
MouseArea{
id: dragArea
anchors.fill: parent
onPressed: root.dragStart = Qt.point(dragArea.mouseX,dragArea.mouseY)
onMouseXChanged: move()
onMouseYChanged: move()
function move(){
var offset = Qt.point(dragArea.mouseX-root.dragStart.x, dragArea.mouseY-root.dragStart.y)
root.moved(offset)
console.log(offset)
}
}
}
//MainWindow.cpp
void MainWindow::moveQml(QPointF offset){
ui->quickWidget->move(ui->quickWidget->pos()+offset.toPoint());
}
注册了BroadCastReceiver
。
在文档中,它说
广播操作:本地蓝牙适配器的状态已更改。 例如,蓝牙已打开或关闭。 始终包含额外字段EXTRA_STATE和EXTRA_PREVIOUS_STATE
分别包含新旧州。
现在,我如何使用EXTRA_STATE和EXTRA_PREVIOUS_STATE?
答案 0 :(得分:1)
来自here:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_OFF:
//Bluetooth off
break;
case BluetoothAdapter.STATE_TURNING_OFF:
//Turning Bluetooth off...
break;
case BluetoothAdapter.STATE_ON:
//Bluetooth on
break;
case BluetoothAdapter.STATE_TURNING_ON:
//Turning Bluetooth on...
break;
}
}
}
};