标签: bluetooth

以编程方式连接到配对的蓝牙设备

有没有办法使用Android SDK以编程方式连接到已配对的蓝牙设备?

换句话说:我可以进入设置 - >无线和网络 - >蓝牙设置,然后点击设备(列为"已配对但未连接"),此时它将连接.我希望能够以编程方式执行此操作,但是没有办法实现此目的.

我看到了创建RFCOMM套接字的选项,对于SPP设备,我假设它也会做连接部分,但是对于A2DP设备,实际数据传输将由OS处理,而不是由我的应用程序,我认为这不适用?

android bluetooth

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

Android蓝牙示例

任何人都可以给我Android Bluetooth通信教程链接或提示吗?请不要告诉我参考蓝牙的例子,我只能理解如何发现和连接设备,但不知道如何通过蓝牙发送和接收数据.

我实际上正在开发一个Android和嵌入式Bluetooth设备项目.请帮帮我..

android bluetooth

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

在Android上使用蓝牙的服务发现失败异常

我目前正在研究一种通过蓝牙连接到仪器的Android应用程序,需要编写字符串命令并接收字符串响应.目前我通过Wi-Fi进行TCP/IP连接/读/写工作,现在尝试实现蓝牙.但我遇到了一些障碍.我一直在网上搜索试图找到类似的东西的例子,并没有运气.我一直在使用Android开发人员资源示例:蓝牙聊天作为我的主要参考点.

我当前的代码似乎工作..然后它会在连接点抛出Service Discovery Failed异常.我正在使用DeviceListActivity该类来发现和选择我想要连接的设备.它返回anActivityResult,然后我的蓝牙类等待它处理它,然后连接到它.下面的代码几乎与蓝牙聊天应用程序相同.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(!m_BluetoothAdapter.isEnabled())
    {
        m_BluetoothAdapter.enable();
    }
    switch (requestCode) {
        case REQUEST_CONNECT_DEVICE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                // Get the device MAC address
                String address = data.getExtras()
                                     .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
                // Get the BLuetoothDevice object
                BluetoothDevice device = m_BluetoothAdapter.getRemoteDevice(address);
                // Attempt to connect to the device
                connect(device);
            }
            break;

        case REQUEST_ENABLE_BT:
            // When the request to enable Bluetooth returns
            if (resultCode …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth

49
推荐指数
2
解决办法
6万
查看次数

如何获取可用蓝牙设备列表?

我目前正在创建一个可以使用蓝牙设备的iPhone应用程序(Xcode 4.3.1,IOS 5)!这个应用程序的主要目标是室内导航(建筑物内的GPS不是很准确).

我在这里看到的唯一解决方案(将我的应用程序保存在AppStore上)是尝试扫描可用的蓝牙设备!

我尝试使用CoreBluetooth框架,但我没有获得可用设备的列表!也许我没有正确使用这些功能

#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>

@interface AboutBhyperView : UIViewController <CBPeripheralDelegate, CBCentralManagerDelegate>
{
    CBCentralManager *mgr;
}
@property (readwrite, nonatomic) CBCentralManager *mgr;
@end



- (void)viewDidLoad
{
    [super viewDidLoad];

    mgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {


    NSLog([NSString stringWithFormat:@"%@",[advertisementData description]]);
}

-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
    NSLog(@"This is it!");
}


- (void)centralManagerDidUpdateState:(CBCentralManager *)central{ 
    NSString *messtoshow;

    switch (central.state) {
        case CBCentralManagerStateUnknown:
        {
            messtoshow=[NSString stringWithFormat:@"State unknown, update imminent."];
            break;
        }
        case CBCentralManagerStateResetting:
        { …
Run Code Online (Sandbox Code Playgroud)

bluetooth ios core-bluetooth

49
推荐指数
3
解决办法
8万
查看次数

使用BlueZ堆栈作为外围设备(广告商)

  • 目标:使用BlueZ和蓝牙4LE加密狗创建一个外围设备,宣传相当于"Hello World"的蓝牙.

  • 我在哪里:我目前有BlueZ堆栈设置和下载,我可以使用hci工具识别并看到蓝牙适配器.我已经使用了hciconfig leadv,但我只是不太了解它/了解正在发生的事情.

  • 我认为我需要什么帮助:我需要进入下一步.如果有人能指出我对一个好的资源,请指导我,或任何事情,非常感谢.如果我需要做额外的腿(搜索)工作,我可以,但我已经用我能想到的这个问题的许多不同衍生物来搜索Google和SO.

*我将此标记为CoreBluetooth,希望可能是iOS开发者在某些时候对此进行了修改.

编辑:回应评论,说明我的最终目标似乎是谨慎的.我最终希望通过加密狗广告最简单的简单消息/信号,并在iOS设备(CoreBluetooth)上进行选择.我已经能够让iOS方面运行良好(与Linux方面相比,大量文档)但对我来说困难的部分是将此适配器设置为外设.BlueZ堆栈对我来说是一个可怕的谜.

编辑:经过更多的挖掘,我最终偶然发现了这篇文章:Raspberry Pi蓝牙4.0连接.这使我走向GATT服务器的主题,我将继续追求这个话题.

编辑:好吧,所以我继续学习.在过去的几天里,我深入研究了hci*,sdptool和gatttool工具.我已经到了能够设置适配器做广告的程度,"hciconfig hci0 leadv".此时,我可以成功"看到"适配器,但我实际上无法读取任何内容.我甚至没有看到友好的名字.我将保持卡车运输,但一如既往,任何帮助/建议都非常受欢迎.

编辑:相关链接,关于iOS的蓝牙LE的可靠概述. https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/AboutCoreBluetooth/Introduction.html#//apple_ref/doc/uid/TP40013257-CH1-SW1

最后编辑:嘿所有,这个链接涵盖了如何使用Raspberry Pi + BlueZ创建iBeacon ... http://www.wadewegner.com/2014/05/create-an-ibeacon-transmitter-with-the-raspberry -pi /

linux bluetooth core-bluetooth bluetooth-lowenergy bluez

49
推荐指数
2
解决办法
5万
查看次数

在.connect()之后如何防止Android蓝牙RFCOMM连接立即死亡?

这个问题已经解决了!非常感谢布拉德,丹尼斯和瘾君子!你是英雄!:)

这是工作代码.它连接到Zeemote并从中读取数据.

=====代码=====

public class ZeeTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            for (int i = 0; i < 3; i++) {
                test();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private boolean connected = false;
    private BluetoothSocket sock;
    private InputStream in;
    public void test() throws Exception {
        if (connected) {
            return;
        }
        BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
            getRemoteDevice("00:1C:4D:02:A6:55");
        Method m = zee.getClass().getMethod("createRfcommSocket",
            new Class[] { int.class });
        sock = (BluetoothSocket)m.invoke(zee, Integer.valueOf(1));
        Log.d("ZeeTest", …

android bluetooth motorola rfcomm

48
推荐指数
3
解决办法
6万
查看次数

蓝牙嗅探器 - 最好是mac osx

我试图找到一个蓝牙数据包嗅探器来捕获设备附近的蓝牙信号.我想这个应用程序在mac osx上工作.我一直很难找到任何东西,所以我的要求现在很低 - 显示信号强度和mac地址将是一个良好的开端.

macos bluetooth packet-capture sniffer packet-sniffers

47
推荐指数
5
解决办法
6万
查看次数

检查Android中是否启用了蓝牙时出错(REQUEST_ENABLE_BT无法解析为变量)

我正在尝试这样做:

    BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
    if (bt == null){
        //Does not support Bluetooth
        status.setText("Your device does not support Bluetooth");
    }else{
        //Magic starts. Let's check if it's enabled
        if (!bt.isEnabled()){
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        }   
    }
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

REQUEST_ENABLE_BT无法解析为变量

我该如何解决?

android bluetooth

47
推荐指数
2
解决办法
4万
查看次数

Android 6.0上的蓝牙低功耗startScan找不到设备

我正在使用Nexus 5开发一个使用蓝牙低功耗的应用程序.它在Lollipop上工作,现在它不能用于Marshmallow.我在清单和活动中的runTime上设置了ACCESS_COARSE_LOCATION和ACCESS_FINE_LOCATION权限.

这是ScanFilters列表:

mScanFilterTest = new ScanFilter.Builder().build();
mScanFilter = new ArrayList<ScanFilter>();
mScanFilter.add(mScanFilterTest);
Run Code Online (Sandbox Code Playgroud)

这些是设置:

mScanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).setReportDelay(0)
                .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).build();
Run Code Online (Sandbox Code Playgroud)

这些是我的回调:

 mBLEScan = new ScanCallback() {
     @Override
     public void onScanResult(int callbackType, ScanResult result) {
         super.onScanResult(callbackType, result);
         Log.i(TAG, "******************************************");
         Log.i(TAG, "The scan result " + result);
         Log.i(TAG, "------------------------------------------");
         }
     };
Run Code Online (Sandbox Code Playgroud)

这是我的电话:

mBluetoothLeScanner.startScan(mScanFilter, mScanSettings, mBLEScan);
Run Code Online (Sandbox Code Playgroud)

它开始扫描但没有找到任何设备.请帮我!!!!

android bluetooth bluetooth-lowenergy android-6.0-marshmallow

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

Android +配对设备通过蓝牙编程

我想发现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)

android bluetooth

45
推荐指数
3
解决办法
14万
查看次数