相关疑难解决方法(0)

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万
查看次数

获取 Android 上可用的蓝牙设备列表

这个问题中,@nhoxbypass 提供了此方法,用于将找到的蓝牙设备添加到列表中:

private BroadcastReceiver myReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Message msg = Message.obtain();
            String action = intent.getAction();
            if(BluetoothDevice.ACTION_FOUND.equals(action)){
               //Found, add to a device list
            }           
        }
    };
Run Code Online (Sandbox Code Playgroud)

但是,我不明白如何获得对找到的设备的引用,这该怎么做?

我无权对原始问题发表评论,所以我选择在这里扩展它。

java android bluetooth android-bluetooth

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

标签 统计

android ×2

bluetooth ×2

android-bluetooth ×1

java ×1