我已经实现了一个服务,我处理状态更改(连接,断开连接,onServiceDiscoverd,onCharacteristicChange等)并通过gatt服务器从另一个设备接收数据.
我的问题是,使用Greenrobot Eventbus 在服务和活动之间替换广播接收器可以有效地处理事件吗?
android android-service bluetooth-lowenergy android-broadcast greenrobot-eventbus
我不确定我做错了什么。当传递不同类型的输入时,如何防止 Test 类接受和抛出错误。我正在使用Python 3.9.2
from dataclasses import dataclass, fields
@dataclass
class Test:
a: str = 'a'
b: int = 1
t = Test(2, 'b')
print(fields(t))
print(type(t.a))
print(type(t.b))
# output
# (venv) D:\Playground>python dataClassesTest.py
# (Field(name='a',type=<class 'str'>,default='a',default_factory=<dataclasses._MISSING_TYPE object at 0x00000232952D5880>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='b',type=<class 'int'>,default=1,default_factory=<dataclasses._MISSING_TYPE object at 0x00000232952D5880>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
# <class 'int'>
# <class 'str'>
Run Code Online (Sandbox Code Playgroud) 我有3个组成部分。
Activity1 具有用于连接和断开BLE连接的按钮
Activity2 需要从BLE设备获取数据。
服务 所有连接逻辑(例如getRemoteDevice(),connectGatt等)都属于服务。
Activity1通过绑定服务连接到BLE设备。
Intent gattServiceIntent = new Intent(mContext,BleService.class);//In Activity1 context
bindService(gattServiceIntent, mServiceConnection,BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)
并在按下按钮后立即连接到ble设备。
现在,当我从Activity1移到Activity2时,我将取消绑定Activity1中的服务。
mContext.unbindService(mServiceConnection);//In Activity1 context
Run Code Online (Sandbox Code Playgroud)
现在如何在Activity2中使用现有的BLE设备连接?
我的临时解决方案:
当新的服务实例从Activity2上下文绑定到Activity2时,我将重新连接 BLE设备。(我不想要。)
在Activity2中,我正在检查我的服务是否已经在运行(如果未运行),那么我将从Activity2上下文中再次绑定该服务。
if(!isMyServiceRunning(BleWrapper.class)){
Intent wrapperServiceIntent = new Intent(mContext,BleWrapper.class);
bindService(wrapperServiceIntent,mBLEWrapperServiceConnection,BIND_AUTO_CREATE);
}else{
Log.w(LOGTAG, "Service already connected. In onCreate");
}
Run Code Online (Sandbox Code Playgroud)
在ServiceConnection回调下的onServiceConnected()中触发连接
@Override
public void onServiceConnected(ComponentName componentName,IBinder service) {
mBluetoothLeService = ((BleWrapper.LocalBinder) service).getService();
if (!mBluetoothLeService.initialize()) {
showAlertDialog(getString(R.string.ble_not_supported_on_this_device));
}else {
mBluetoothLeService = …Run Code Online (Sandbox Code Playgroud) 我有2列的客户表
CREATE TABLE clients
(
client_id serial primary key,
name VARCHAR(40) not null
)
Run Code Online (Sandbox Code Playgroud)
我有一个JSON数据像
[{client_id:"1",name:"Rick"},{client_id:"2",name:"Carlin"}]
Run Code Online (Sandbox Code Playgroud)
现在,我需要使用此json进行解析并将其插入到我的客户表中。我如何使用jsp servlet和postgres数据库做到这一点。
我有这个字符串
my $word = "Chase_^%798(987%55,.#*&^*&Chase_$&^**&(()%%hjjlhh";
Run Code Online (Sandbox Code Playgroud)
期望的输出是
Chase_^%798(987%55,.#*&^*& Chase_$&^**&(()%%hjjlhh
字符串"Chase_"是我应该将它们分开的唯一线索.使用split我失去了字符串"Chase_".然后我应该连接它们.我对如何分割它没有任何想法,但也"Chase_"应该存在字符串
我的文件夹结构看起来像
D:
|- Folder1
|- File1
|- Folder2
|- File2
Run Code Online (Sandbox Code Playgroud)
输出:
D:
|- Directory1 <- renamed
|- File1
|- Directory2 <- renamed
|- File2
Run Code Online (Sandbox Code Playgroud)
问题是如何将文件夹重命名为一级?
运行应用程序后控制台中显示的错误粘贴在下面
18:46:00.752 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
18:46:00.754 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
18:46:00.754 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/D:/Automation/sts/stsworkspace/BduckApp-1/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | …Run Code Online (Sandbox Code Playgroud) 我是perl的新手.无论如何,我试图调试自己.但我无法指出它
语法错误是
Bareword found where operator expected at D:\DevelopmentLab\softwares\sc-master\sc.pl line 468, near "s%/%_%gr"
syntax error at D:\DevelopmentLab\softwares\sc-master\sc.pl line 468, near "s%/%_%gr"
Execution of D:\DevelopmentLab\softwares\sc-master\sc.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
代码是
sub getBackupFileName {
my ($containerName, $volume) = @_;
my $backupFileName = $volume =~ s%/%_%gr;
return "${containerName}_${backupFileName}.tar";
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将受到高度赞赏..
android ×2
java ×2
perl ×2
android-ble ×1
directory ×1
json ×1
jsp ×1
postgresql ×1
python-3.x ×1
regex ×1
rename ×1
servlets ×1
spring-boot ×1
sql ×1