我想发现bluetooth范围内的设备,列表并在点击时与它们配对.当我点击我要配对的设备名称时,我使用了以下代码,但它只关闭了应用程序.
我想知道我的代码中的错误或任何其他方式来做我需要的.
package com.marakana;
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class BluetoothDemo extends Activity {
// Debugging
private static final String TAG = "DeviceListActivity";
private static final boolean D = true;
// Return Intent extra
public static String EXTRA_DEVICE_ADDRESS = "device_address";
// Member fields
private …Run Code Online (Sandbox Code Playgroud) 我目前正在开发基于蓝牙低功耗设备的iOS应用程序.为了获得唯一的标识符来比较外设,我必须得到外设的MAC地址.
据观察,外围设备的UUID属性在iOS设备上不同,并且外围设备也需要获得UUID,它必须至少连接一次主设备.由于我必须处理登记入住,我不想建立连接.当我浏览蓝牙服务门户时,我发现设备信息本身就是一项服务,除非在主iOS设备和外围蓝牙低功耗设备之间建立了连接,否则无法检索该服务.
我发现在Android中我们获取设备的全部信息,包括其MAC地址(使用getAddress()),当我们从扫描设备获得响应时.
我没有在CBPeripheral类中找到与设备地址相关的任何属性.获得唯一参数的另一种方式是定制广告数据以发送关于设备的附加信息,这需要在固件方面进行更多工作.
那么在iOS中有什么办法可以在不建立连接的情况下获得蓝牙低能耗外设的MAC地址吗?
任何帮助将不胜感激.
我们需要一台可以通过蓝牙或wifi连接到Android手机的便携式打印机(手持设备,这很重要).
我有一个应用程序,我以编程方式控制蓝牙配对和取消配对.我可以在连接前配对,然后取消配对.我需要这样做的原因是我的申请特定而不是我的问题范围.
基本上我正在做的是:
ib,以IBluetooth在对象描述这个答案android.bluetooth.device.action.PAIRING_REQUESTib.createBond(address)ib.setPin(address, pinBytes)从BroadcastReceiver内部呼叫无论如何,这种方法效果很好,除了当我进行配对时,我在状态栏中收到通知,要求用户输入PIN以完成配对.但这实际上是不必要的,因为当用户看到这个时,我的应用已经使用过setPin().我真的很喜欢这个通知要么a)根本不出现,要么b)以某种方式自动被解雇.
我意识到这可能是不可能的,但我想如果有人有创意,我会问.
Android的蓝牙低功耗API实现1种方法连接到该设备connectGatt(),但2种方法来关闭连接disconnect()和close().
文件说:
disconnect():断开已建立的连接,或取消当前正在进行的连接尝试.
close():应用程序应在使用此GATT客户端完成后尽早调用此方法.
BluetoothGatt.java的源代码显示close()取消注册应用程序,disconnect()断开客户端连接.然而,它没有说明实际意味着什么.我的意思是,如果只有一种方法可以连接到客户端,为什么有两种方法可以关闭/断开连接?
我正在使用Core Bluetooth API在iOS 7中编写测试应用程序.当我测试应用程序时,我发现我收到以下警告消息:
TestBluetooth [626:60b] CoreBluetooth [API MISUSE]只能在开机状态下接受命令
后来我调试了app并发现,警告来自以下代码行:
[manager scanForPeripheralsWithServices:array options:scanOptions];
Run Code Online (Sandbox Code Playgroud)
那么有人可以告诉我为什么我在控制台中收到此消息?
我周围有蓝牙4.0 Android设备,但这个应用程序并没有发现它们作为外围设备.那么为什么它不发现蓝牙4.0 LE Android设备作为外围设备?
我想使用.NET Core中的蓝牙LE功能(特别是BluetoothLEAdvertisementWatcher)来编写将信息记录到文件的扫描程序.这是作为桌面应用程序运行,最好是作为命令行应用程序运行.
System.IO.StreamWriter(string)这样的构造函数显然不可用.如何创建文件并写入文件?
我会很高兴能够做一个System.Console.WriteLine(字符串),但似乎在.NET Core下也没有.
更新:为了澄清,如果我有一个看起来像这样运行的程序没有错误,我将参加比赛.
using System;
using Windows.Devices.Bluetooth.Advertisement;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
BluetoothLEAdvertisementWatcher watcher = new BluetoothLEAdvertisementWatcher();
Console.WriteLine("Hello, world!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新2:这是project.json文件:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
Run Code Online (Sandbox Code Playgroud)
该命令的输出dotnet -v run包含此错误消息:
W:\src\dotnet_helloworld>dotnet -v run
...
W:\src\dotnet_helloworld\Program.cs(2,15): error CS0234: The type or namespace name 'Devices' does …Run Code Online (Sandbox Code Playgroud) 我有一个非A2DP单耳BT耳机(Plantronics 510),并希望与我的Android HTC Magic一起使用,以收听播客/有声读物等低质量音频.
经过大量的谷歌搜索,我发现只有电话呼叫音频可以路由到非A2DP BT耳机.(我想知道您是否找到了将各种音频路由到非A2DP BT耳机的现成解决方案)
所以我想,不知怎的,我可以通过编程方式将音频引导到携带电话音频的流.这样我就会欺骗手机将我的mp3音频传输到我的BT耳机.我写了以下简单的代码.
import android.content.*;
import android.app.Activity;
import android.os.Bundle;
import android.media.*;
import java.io.*;
import android.util.Log;
public class BTAudioActivity extends Activity
{
private static final String TAG = "BTAudioActivity";
private MediaPlayer mPlayer = null;
private AudioManager amanager = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
amanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
amanager.setBluetoothScoOn(true);
amanager.setMode(AudioManager.MODE_IN_CALL);
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(new FileInputStream(
"/sdcard/sample.mp3").getFD());
mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
mPlayer.prepare();
mPlayer.start();
} catch(Exception e) {
Log.e(TAG, e.toString());
}
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过Linux机器与BLE模块通信(该模块正在运行心率配置文件).到目前为止,除了听取通知和指示(例如,听取心率测量通知)之外,我已经能够做我需要的一切.我正在使用内核版本3.5和bluez-5.3.
到目前为止使用的成功命令:
hcitool lescan
hcitool lecc
gatttool -b <Mac Address> --primary
gatttool -b <MAC Address> --characteristics
gatttool -b <MAC Address> --char-read
gatttool -b <MAC Address> --char-desc
gatttool -b <MAC Address> --interactive
Run Code Online (Sandbox Code Playgroud)
命令失败:
gatttool -b <MAC Address> --listen
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
我在Nexus 7上使用Android 4.4.2.我有一个蓝牙低功耗外设,其服务在重新启动时会发生变化.Android应用程序调用BluetoothGatt.discoverServices().然而,Android只查询外围设备一次以发现服务,后续调用discoverServices()会导致第一次调用的缓存数据,甚至断开连接之间.如果我禁用/启用Android bt适配器,则discoverServices()通过查询外设来刷新缓存.有没有一种程序化的方法来强制Android刷新其'ble服务缓存而不禁用/启用适配器?