小编mha*_*per的帖子

如何在Swift中初始化对象期间将self传递给初始化程序?

我有以下代码:

import CoreBluetooth

class BrowserSample: NSObject, CBCentralManagerDelegate {
    let central : CBCentralManager

    init() {
        central = CBCentralManager(delegate: self, queue: nil, options: nil)
        super.init()
    }

    func centralManagerDidUpdateState(central: CBCentralManager!)  { }
}
Run Code Online (Sandbox Code Playgroud)

如果我central =之前把线放super.init(),那我得到错误:

self used before super.init() call
Run Code Online (Sandbox Code Playgroud)

如果我把它放在后面,我得到错误:

Property self.central not initialized at super.init call
Run Code Online (Sandbox Code Playgroud)

所以,我很困惑.我该怎么做呢?

ios core-bluetooth swift

11
推荐指数
1
解决办法
5229
查看次数

在RadioButton旁边添加EditText

我有一个自定义DialogPreference子类,我希望有一个RadioGroup带有三个单选按钮.前两个是RadioButton带有标题的vanilla 组件,但是对于第三个我想EditText直接放在它的右侧,所以我可以在选择该按钮时输入自定义值.

我已经尝试将第三个按钮放入水平线LinearLayout,EditText然后第三个按钮不再参与父节点RadioGroup.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <RadioGroup
            android:id="@+id/lactate_radio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        <RadioButton
                android:id="@+id/lactate_default_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/lactate_default_value"/>

        <RadioButton
                android:id="@+id/lactate_calibrated_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/lactate_calibrated_value" />
        <LinearLayout android:orientation="horizontal"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
            <RadioButton
                    android:id="@+id/lactate_custom_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/lactate_custom_value"/>

            <EditText
                    android:id="@+id/lactate_custom_value_edit_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

        </LinearLayout>
    </RadioGroup>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

自定义DialogPreference的屏幕截图

我也试过以LinearLayout编程方式添加它,但仍然有相同的行为.有没有办法做到这一点,也许是通过明确告诉父母RadioGroup关于第三个按钮或通过某种方式EditText适当地定位,而不使用水平LinearLayout?否则,我想我必须编写一个RadioButton应该是真正的派对的子类!

android android-edittext

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

检测BLE设备是否可在Android上连接

我正在开发一个配置信标的项目.通电一段时间后,信标变为不可配置,直到电源循环.为了显示可配置信标的列表,我正在查看某些特征(蓝牙设备名称,广告包中的某些制造商数据).我还需要知道它是否是"可连接的",即设备的BLE通告数据包中的PDU类型是否表明它是可连接的.我已经在Android 4.X和5.X中搜索了高低的Android蓝牙类,并且无法找到能告诉我这些信息的任何内容.

我意识到确定信标可连接性的一种方法是连接到它,例如:device.connectGatt(...).但是,我已经看到有时需要花费两分钟才能onConnectionStateChange回复STATE_DISCONNECTED.此外,在一个环境中可能存在许多这些信标,并且连接到可能可配置的每个信标将是低效的.

可以在回调方法中advertisementData的键下的字典中找到此属性的iOS等效项.CBAdvertisementDataIsConnectableCBCentralManagerDelegatecentralManager:didDiscoverPeripheral:advertisementData:RSSI

因此,问题是:在Android上是否有办法确定BLE设备是否可以与广告数据或扫描结果"连接"或......?

android bluetooth-lowenergy

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

Android搜索onCancel()侦听器未被调用

在我的主Activity的onCreate()方法中,当用户取消搜索对话框而不发出搜索时,我设置了对Activity的onCancel()方法的回调(我相信).这是我的注册码:

SearchManager searchManager = (SearchManager) getApplicationContext().getSystemService(Context.SEARCH_SERVICE);
searchManager.setOnCancelListener(this);
Run Code Online (Sandbox Code Playgroud)

我的Activity实现了SearchManger.OnCancelListener,我的onCancel()方法当前是一个Log.d()语句.但是,每当我取消搜索对话框(例如使用后退按钮)时,都不会调用此方法.

需要说明的是,搜索功能在执行时效果很好.我只想在用户取消搜索对话框时收到通知,以便我采取行动.此外,我正在使用默认的Android搜索对话框,该对话框在请求时显示在屏幕顶部.

是否需要某种配置,例如在AndroidManifest.xml中,以支持此回调?或者我只是缺少/做一些愚蠢的事情(完全可能)?

android android-searchmanager

3
推荐指数
1
解决办法
2406
查看次数

从OS X上的shell脚本获取手机上EXTERNAL_STORAGE环境变量的值

我希望能够EXTERNAL_STORAGEbuild.xmlOS X上运行的ant 脚本中获取我的Android手机上的变量值,以便随后我可以adb push在手机上的该位置执行一个文件.

当我被戴上手机时,我可以看到价值很好:

$ adb shell
shell@android:/ $ echo $EXTERNAL_STORAGE
/mnt/sdcard
Run Code Online (Sandbox Code Playgroud)

当我尝试使用单行adb shell命令在OS X上获取该值时,我什么也得不到:

$ adb shell "echo $EXTERNAL_STORAGE"
Run Code Online (Sandbox Code Playgroud)

有关如何使其工作的任何想法?

android adb

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