小编Fra*_*leo的帖子

简单的 Android BLE 扫描仪

我正在尝试创建一个简单的 android 应用程序,我可以使用它扫描低功耗蓝牙 (BLE) 设备并将名称打印为日志。主要活动是非常基本的,我不需要检查,我想这没问题。扫描开始,但我没有结果。

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.s1080994.tid.findble">


    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />


    <uses-feature
        android:name="android.hardware.bluetooth_le"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

主活动.java

public class MainActivity extends AppCompatActivity {

    private BluetoothAdapter mBluetoothAdapter  = null;
    private BluetoothLeScanner mBluetoothLeScanner = null;

    public static final int REQUEST_BT_PERMISSIONS = 0;
    public static final int REQUEST_BT_ENABLE = 1;

    private boolean mScanning = false;
    private Handler mHandler …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy

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

标签 统计

android ×1

bluetooth ×1

bluetooth-lowenergy ×1