小编Ame*_*sys的帖子

Android - 蓝牙发现找不到任何设备

我目前正在开发一个小应用程序,以开始使用蓝牙Android API提供的服务.

编辑 - >答案:

似乎问题是由于特定的Nexus 5设备.好像他们的蓝牙接收器不能正常工作.以下解决方案适用于其他设备

备注:

  1. 我在这里阅读了文档:http://developer.android.com/guide/topics/connectivity/bluetooth.html 以及本教程的以下源代码http://www.londatiga.net/it/programming/android/how-to-programmatically-scan-or-discover-android-bluetooth-device /位于/ lorensiuswlt/AndroBluetooth下的github上

  2. 我已经完成了几乎所有感兴趣的功能(例如检查适配器是否存在,启用/禁用蓝牙,查询配对的divices,设置适配器是否可发现).

问题:

实际上,当我启动.onDiscovery()方法时,找不到任何设备,即使在我的Nexus 5上的设置/蓝牙中找到了设备.

我是如何处理的:

public class MainActivity extends AppCompatActivity {
private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

...

protected void onCreate(Bundle savedInstanceState) {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(mReceiver, filter); 
}
Run Code Online (Sandbox Code Playgroud)

过滤器工作良好,据我可以尝试,即ACTION_STATE_CHANGED(蓝牙启用)和两个ACTION_DISCOVERY _***.

然后成功地调用以下方法:

public void onDiscovery(View view)
{
    mBluetoothAdapter.startDiscovery();
}
Run Code Online (Sandbox Code Playgroud)

然后我有我的蓝牙接收器:

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) …
Run Code Online (Sandbox Code Playgroud)

android bluetooth receiver

39
推荐指数
2
解决办法
3万
查看次数

在 PySpark 中提取多个正则表达式匹配项

我目前正在开发一个正则表达式,我想在 PySpark Dataframe 的列上运行它。

该正则表达式仅用于捕获一组,但可以返回多个匹配项。我遇到的问题是,PySpark 本机正则表达式的函数(regexp_extract 和 regexp_replace)似乎只允许组操作(通过 $ 操作数)。

有没有一种方法可以本地(PySpark函数,没有python的基于re.findall的udf)获取与我的正则表达式匹配的子字符串列表(我不是在谈论第一个匹配中包含的组)?

我想做这样的事情:

my_regex = '(\w+)'
# Fetch and manipulate the resulting matches, not just the capturing group
df = df.withColumn(df.col_name, regexp_replace('col_name', my_regex, '$1[0] - $2[0]'))
Run Code Online (Sandbox Code Playgroud)

$1 代表第一个匹配的数组,依此类推......

您可以尝试以下正则表达式输入来查看我希望获取的匹配项的示例。

2 AVENUE DES LAPINOUS
Run Code Online (Sandbox Code Playgroud)

它应该返回 4 个不同的匹配项,每个匹配项包含 1 个组。

python regex string apache-spark pyspark

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

apache-spark ×1

bluetooth ×1

pyspark ×1

python ×1

receiver ×1

regex ×1

string ×1