搜索附近的蓝牙设备

本文介绍了如何在开启蓝牙后,通过指定步骤搜索并连接到附近的蓝牙设备,包括添加必要的权限和实现相关代码。
摘要由CSDN通过智能技术生成

.当我们打开蓝牙时搜索附近的蓝牙,步骤如下
在这里插入图片描述
1.添加权限:

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

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

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

2.加入代码

//主布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:textSize="25dp"
        android:text="服务态度"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RatingBar
            android:id="@+id/ratingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:gravity="center_vertical"
            android:numStars="5"
            android:rating="0" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:text="描述相符"/>

        <com.example.ratingbar.RatingBar
            android:id="@+id/ratingbar2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:starCount="5"
            app:starEmpty="@drawable/star_20x20_n"
            app:starFill="@drawable/star_20x20_hl"
            app:starHalf="@drawable/star_20x20_h"
            app:starImageSize="30dp"
            app:starPadding="10dp"
            app:starStep="0.0"
            android:layout_marginLeft="3dp"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/teview_evaluate"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="#F71515"
            android:textSize="19dp" />
    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值