ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

基于Android Studio经典蓝牙APP---继上一次的完善版

2022-03-20 15:59:34  阅读:164  来源: 互联网

标签:xml 文件 工程 APP 程序 --- Studio 下载


基于Android Studio经典蓝牙APP—继上一次的完善版

  • 考虑到好友网友们反馈的问题总结了以下几点:
    1、工程下载爆红:版本问题—gradle:4.1.1。
    2、无接收数据功能,怎么实现:这里我会附上程序大家自行理解.
    3、程序突然闪退问题:那是因为发送和接收广播等线程上起冲突了,大家看修改后的程序进行理解。
    4、界面上控件的颜色调不了:
    res/values/themes.xml下的
<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

改为:

<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
  • 这里我把我修改完善好的程序贴上并做相关的解释,还会附加上工程文件给大家自行下载。

如果不是直接使用我的工程文件,而是下自己手写一遍的,只需要我下面贴上的程序即可。
AndroidManifest.xml

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

    <!-- 管理蓝牙需要 -->
    <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" />
    <!--        android:icon="@mipmap/ic_launcher"-->
    <application
        android:allowBackup="true"
        android:icon="@drawable/huawei1"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Mybluetooth_finish">
        <meta-data
            android:name="com.google.android.actions"
            android:resource="@xml/frame" />

        <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>

activity_main.xml

<?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"
    android:orientation="vertical">
    <!--流式布局一-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/Reminder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#F42C2C"
            android:gravity="center"
            android:text="@string/reminder"
            android:textSize="15dip" />
    </LinearLayout>
    <!--流式布局二-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@drawable/frame3"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/Broadcast"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame1"
            android:gravity="center"
            android:text="@string/Broadcast"
            android:textSize="10dp" />

        <Button
            android:id="@+id/CloseBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame2"
            android:gravity="center"
            android:onClick="CloseBlueTooth"
            android:text="@string/close"
            android:textSize="10dp" />

        <Button
            android:id="@+id/OpenBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame5"
            android:gravity="center"
            android:onClick="OpenBlueTooth"
            android:text="@string/open"
            android:textColor="#37E2F8"
            android:textSize="13dp" />

        <Button
            android:id="@+id/DiscoveryBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/myframe"
            android:gravity="center"
            android:text="@string/discovery"
            android:textSize="10dp" />
    </LinearLayout>
    <!--流式布局三-->
    <LinearLayout
        android:id="@+id/beizhu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#C3C3C3"
            android:gravity="center"
            android:text="@string/divide" />
    </LinearLayout>
    <!--流式布局四-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/search">

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <TextView
        android:id="@+id/receive"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:background="@drawable/receive"

        android:textSize="22dp"
        android:textColor="#FF6297" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal">


        <EditText
            android:id="@+id/send"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/keyboard"
            android:textColor="#00B0FF" />
    </LinearLayout>

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

        <Button
            android:id="@+id/button_send"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame2"
            android:text="发送"
            android:textColor="#e069F0AE"
            android:textSize="15dp" />

        <Switch
            android:id="@+id/button_open_close1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame4"
            android:text=" 电磁阀"
            android:textSize="15dp"
            android:textColor="#FBE204" />

        <Switch
            android:id="@+id/button_open_close2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame3"
            android:text=" LED"
            android:textSize="15dp"
            android:textColor="#FBE204" />

        <Switch
            android:id="@+id/button_open_close3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame1"
            android:text=" 电磁锁"
            android:textSize="15dp"
            android:textColor="#FBE204" />
    </LinearLayout>



</LinearLayout>

MainActivity.java

<?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"
    android:orientation="vertical">
    <!--流式布局一-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/Reminder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#F42C2C"
            android:gravity="center"
            android:text="@string/reminder"
            android:textSize="15dip" />
    </LinearLayout>
    <!--流式布局二-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@drawable/frame3"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/Broadcast"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame1"
            android:gravity="center"
            android:text="@string/Broadcast"
            android:textSize="10dp" />

        <Button
            android:id="@+id/CloseBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame2"
            android:gravity="center"
            android:onClick="CloseBlueTooth"
            android:text="@string/close"
            android:textSize="10dp" />

        <Button
            android:id="@+id/OpenBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/frame5"
            android:gravity="center"
            android:onClick="OpenBlueTooth"
            android:text="@string/open"
            android:textColor="#37E2F8"
            android:textSize="13dp" />

        <Button
            android:id="@+id/DiscoveryBT"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/myframe"
            android:gravity="center"
            android:text="@string/discovery"
            android:textSize="10dp" />
    </LinearLayout>
    <!--流式布局三-->
    <LinearLayout
        android:id="@+id/beizhu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#C3C3C3"
            android:gravity="center"
            android:text="@string/divide" />
    </LinearLayout>
    <!--流式布局四-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@drawable/search">

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <TextView
        android:id="@+id/receive"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:background="@drawable/receive"

        android:textSize="22dp"
        android:textColor="#FF6297" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal">


        <EditText
            android:id="@+id/send"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/keyboard"
            android:textColor="#00B0FF" />
    </LinearLayout>

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

        <Button
            android:id="@+id/button_send"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame2"
            android:text="发送"
            android:textColor="#e069F0AE"
            android:textSize="15dp" />

        <Switch
            android:id="@+id/button_open_close1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame4"
            android:text=" 电磁阀"
            android:textSize="15dp"
            android:textColor="#FBE204" />

        <Switch
            android:id="@+id/button_open_close2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame3"
            android:text=" LED"
            android:textSize="15dp"
            android:textColor="#FBE204" />

        <Switch
            android:id="@+id/button_open_close3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/frame1"
            android:text=" 电磁锁"
            android:textSize="15dp"
            android:textColor="#FBE204" />
    </LinearLayout>



</LinearLayout>

下图为包含图标、背景颜色、图片等相关程序及程序等的文件,这些在我工程上都是有使用到的,大家第一次写可以先把这些添加上去,熟练后,后面自己再根据需求自行修改。
在这里插入图片描述
下载到手机的现象如下:
在这里插入图片描述
下载工程文件网址为:
https://download.csdn.net/download/morecrazylove/85007899

标签:xml,文件,工程,APP,程序,---,Studio,下载
来源: https://blog.csdn.net/morecrazylove/article/details/123613581

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有