小编Kua*_*att的帖子

在android studio中扫描ble模块(蓝牙4.0)

我正在尝试开发一个应用程序来扫描 BLE 设备。但是,它只扫描一次。我尝试使用 while 循环来循环它,但它挂在那里。扫描部分在继续功能:

package com.example.user.myfriend;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;


public class MainActivity extends ActionBarActivity {
BluetoothAdapter mBluetoothAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {


    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    hello();

}

public void hello() {

    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

        startActivityForResult(enableBluetooth, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy android-bluetooth

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