小编Wun*_*Wun的帖子

onServicesDiscovered状态为129,并且在Android中为BLE连接unstable

我按照蓝牙低能耗页面进行Android 4.3蓝牙低功耗开发

我尝试通过以下代码连接BLE设备:

public void connect(final String address) {
        // TODO Auto-generated method stub
        Log.w(TAG, "BluetoothLeService Connect function.");
        if(mBluetoothAdapter == null || address == null){
            Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        }
        final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
        mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
    }
Run Code Online (Sandbox Code Playgroud)

连接到BLE设备后,它将通过mBluetoothGatt.discoverServices();以下代码发现服务.

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {

        public void onConnectionStateChange(android.bluetooth.BluetoothGatt gatt, int status, int newState) {
            if(mBluetoothGatt == null){
                Log.e(TAG, "mBluetoothGatt not created!");
                return;
            }

            device = gatt.getDevice();
            address = device.getAddress();
            try …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-4.3-jelly-bean

6
推荐指数
1
解决办法
9328
查看次数

自定义UUID在IOS示例中对BLE的意义是什么?

我是iOS开发的新手,并且正在研究Bluetooth Low Energy (BLE, Bluetooth 4.0)IOS.

我研究了这个链接BTLE Central Peripheral Transfer的示例代码.

此链接iOS 7 SDK中还有另一个类似的示例:Core Bluetooth - Practical Lesson

以上两个链接上的应用程序在send and receive the text data两个IOS设备之间进行了讨论BLE.应用程序可以选择一个centralPeripheral,central并将收到从中发送的文本数据Peripheral.

它定义了UUID类似下面的代码header file.

#define TRANSFER_CHARACTERISTIC_UUID    @"08590F7E-DB05-467E-8757-72F6FAEB13D4"
Run Code Online (Sandbox Code Playgroud)

并且在Central连接到之后Peripheral,它发现了特征Peripheral.

如果UUID等于TRANSFER_CHARACTERISTIC_UUID,则使用setNotifyValue:YES类似下面的代码订阅它.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    // Again, we loop through the array, …
Run Code Online (Sandbox Code Playgroud)

bluetooth objective-c ios core-bluetooth bluetooth-lowenergy

5
推荐指数
1
解决办法
3506
查看次数

如何在 swift 中通过 nsuserdefaults 存储像 CBPeripheral 这样的自定义数据?

我正在使用 Swift 进行开发。我想通过存储自定义数据nsuserdefaults

我的自定义数据如下

ConnectedDevice.swift中

import UIKit
import Foundation
import CoreBluetooth
import CoreLocation

class ConnectedDevice : NSObject , NSCoding{

    var RSSI_threshold:NSNumber=0

    var Current_RSSI:NSNumber=0

    var name:String?

    var bdAddr:NSUUID?

    var ConnectState:Bool=false

    var AlertState:Int=0

    var BLEPeripheral : CBPeripheral!

    var DisconnectAddress:[String] = [String]()

    var DisconnectTime:[String] = [String]()

    var Battery:NSInteger=0

    var Location:[CLLocation] = [CLLocation]()

    var AlertStatus:Int!



    func encodeWithCoder(aCoder: NSCoder) {

        aCoder.encodeObject(RSSI_threshold, forKey: "RSSI_threshold")
        aCoder.encodeObject(Current_RSSI, forKey: "Current_RSSI")
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(bdAddr, forKey: "bdAddr")
        aCoder.encodeBool(ConnectState, forKey: "ConnectState")
        aCoder.encodeInteger(AlertState, forKey: "AlertState")
        aCoder.encodeObject(BLEPeripheral, forKey: "BLEPeripheral")
        aCoder.encodeObject(DisconnectAddress, …
Run Code Online (Sandbox Code Playgroud)

nsuserdefaults nscoding ios swift

5
推荐指数
1
解决办法
3394
查看次数

如何在Android中获取当前语言?

在我的 Android 手机语言设置中,我将语言设置为English(United Kingdowm)

我使用以下代码来获取语言:

Log.d(TAG,"getDisplayLanguage = " + Locale.getDefault().getDisplayLanguage());
Log.d(TAG,"getLanguage = " + Locale.getDefault().getLanguage());
Log.d(TAG,"Resources.getLanguage = " + Resources.getSystem().getConfiguration().locale.getLanguage());
Log.d(TAG,"getResources.getLanguage = " + getResources().getConfiguration().locale);
Run Code Online (Sandbox Code Playgroud)

日志显示如下:

getDisplayLanguage = English
getLanguage = en
Resources.getLanguage = en
getResources.getLanguage = en_GB
Run Code Online (Sandbox Code Playgroud)

它没有显示Local.UK

我错过了什么吗?

android local

5
推荐指数
1
解决办法
4174
查看次数

如何在Android中以正确的方式多次观察实时数据?

我有一个 Activity,它会转到片段 A,然后转到片段 B,如下所示。

Activity -> Fragment-A -> Fragment-B

情况一

这两个片段观察相同的 LiveData 以显示如下所示的小吃店。

viewModel.responseData.observe(this, Observer {
            it.getContentIfNotHandled()?.let {
            showSnackBar(it)
}
Run Code Online (Sandbox Code Playgroud)

livedata在视图模型:

var responseData = MutableLiveData<Event<String>>()
responseData.value = Event("$message")
Run Code Online (Sandbox Code Playgroud)

错误: 当我使用上面的代码时。它只显示snackBarat fragment-A。该片段-B无法获得的价值。

情况二

当我将代码更改为以下内容时

viewModel.responseData.observe(this, Observer {
            showSnackBar(it.peekContent())
})
Run Code Online (Sandbox Code Playgroud)

这两个片段都可以获取值。

错误:

关闭片段后再次转动。它显示了snackBar,因为它的值responseData仍然存在。但是我没有发送消息。

Event 来自谷歌的类参考如下:

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-livedata mutablelivedata

5
推荐指数
1
解决办法
3530
查看次数

如何在Android中将“yyyy-MM-dd'T'HH:mm:ssZZZZZ”转换为“yyyy-MM-dd”而不添加一天?

我是用Android开发的

String 的日期是2020-04-23T23:59:59-04:00

并尝试使用以下函数将时间转换为2020-04-23

fun changeDateFormat(strDate:String):String {
    return SimpleDateFormat("yyyy-MM-dd").format(SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ").parse(strDate))
}
Run Code Online (Sandbox Code Playgroud)

但它显示2020-04-24

我错过了什么吗?提前致谢。

android date kotlin

5
推荐指数
1
解决办法
5588
查看次数

为什么在ObjectiveC中参数之前有一个"_"?

我是iOS开发的新手,并且正在研究Bluetooth Low Energy (BLE, Bluetooth 4.0)IOS.

我看到了一些示例代码,如下所示:

@property (strong, nonatomic) CBPeripheralManager *peripheralManager;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Start up the CBPeripheralManager
    _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
}
Run Code Online (Sandbox Code Playgroud)

The question is :

为什么在externalManager之前添加"_" ViewDidload

对不起我的英语和任何愚蠢的......

提前致谢.

objective-c ios

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

如何在 Android 的 OnCompleteListener 中返回值?

我正在尝试像以下代码一样获取智能手机的 GPS:

在 中Activity.java,我使用以下代码获取GPS

private GPSClass gps;
gps.getGPSLocation();
Run Code Online (Sandbox Code Playgroud)

GPSClass.java

public void getGPSLocation(){
        FusedLocationProviderClient mLocationClient = LocationServices.getFusedLocationProviderClient(mContext);
        mLocationClient.getLastLocation().addOnCompleteListener(mContext, new OnCompleteListener<Location>() {
            @Override
            public void onComplete(@NonNull Task<Location> task) {
                if(task.isSuccessful()){
                    mLocation = task.getResult();
                    Log.i("getLocation---LOCATION", mLocation.getLatitude() + "/"
                            + mLocation.getLongitude());

                }
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

但是如何返回值GPSClass.java

我已经尝试更换

public void onComplete
Run Code Online (Sandbox Code Playgroud)

代替

public Location onComplete
Run Code Online (Sandbox Code Playgroud)

但它显示错误

'onComplete(Task<Location>)' in 'Anonymous class derived from com.google.android.gms.tasks.OnCompleteListener' clashes with 'onComplete(Task<TResult>)' in 'com.google.android.gms.tasks.OnCompleteListener'; attempting to use incompatible return type

我错过了什么?如何返回值OnCompleteListener?提前致谢。

android

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

Objective-C何时调用cellForRowAtIndexPath?

我是iOS开发的新手,并为IOS研究蓝牙低功耗(BLE,蓝牙4.0).

我试着添加10个数据tableView.

从日志,它将运行10 timecellForRowAtIndexPath.

The question is :

如何Objective-C的知道它必须运行10 timecellForRowAtIndexPath

是根据numberOfRowsInSection

objective-c ios

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

如何通过Objective-C中的按钮控制自动旋转?

我在发展 Objective-C

我使用以下代码锁定screen orientation并将其设置为UIInterfaceOrientationPortrait.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

但我想screen rotate通过UIButton. 例如,如果电流shouldAutorotateNoYES当我单击 时,它将更改为Button。就像下面的伪代码。

- (IBAction) lock_Auto_rotate:(id)sender {

    if(Autorotate == YES){
       Autorotate = NO;
    }else{
       Autorotate = YES;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何控制auto rotate由一个Button

提前致谢。

autorotate ios

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