Android Bluetooth Serial 项目教程

随笔1周前发布 懿煌子
16 0 0

Android Bluetooth Serial 项目教程

android-bluetooth-serialA library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.项目地址:https://gitcode.com/gh_mirrors/an/android-bluetooth-serial

1. 项目的目录结构及介绍




android-bluetooth-serial/


├── app/


│   ├── build.gradle


│   ├── src/


│   │   ├── main/


│   │   │   ├── java/


│   │   │   │   └── com/


│   │   │   │       └── harryjph/


│   │   │   │           └── bluetoothserial/


│   │   │   │               ├── MainActivity.java


│   │   │   │               └── ...


│   │   │   ├── res/


│   │   │   │   ├── layout/


│   │   │   │   │   ├── activity_main.xml


│   │   │   │   │   └── ...


│   │   │   │   ├── values/


│   │   │   │   │   ├── strings.xml


│   │   │   │   │   └── ...


│   │   │   │   └── ...


│   │   │   └── AndroidManifest.xml


│   │   └── ...


│   └── ...


├── library/


│   ├── build.gradle


│   ├── src/


│   │   ├── main/


│   │   │   ├── java/


│   │   │   │   └── com/


│   │   │   │       └── harryjph/


│   │   │   │           └── bluetoothserial/


│   │   │   │               ├── BluetoothSerial.java


│   │   │   │               └── ...


│   │   │   └── ...


│   └── ...


├── build.gradle


├── settings.gradle


└── ...

目录结构介绍

app/: 包含应用程序的主要代码和资源文件。
src/main/java/com/harryjph/bluetoothserial/: 包含应用程序的主要Java代码。src/main/res/: 包含应用程序的资源文件,如布局文件、字符串资源等。src/main/AndroidManifest.xml: 应用程序的清单文件,定义了应用的组件和权限。 library/: 包含蓝牙串口通信库的代码。
src/main/java/com/harryjph/bluetoothserial/: 包含蓝牙串口通信库的主要Java代码。 build.gradle: 项目的构建脚本。settings.gradle: 项目的设置文件,定义了包含的模块。

2. 项目的启动文件介绍

MainActivity.java




package com.harryjph.bluetoothserial;


 


import android.os.Bundle;


import android.support.v7.app.AppCompatActivity;


 


public class MainActivity extends AppCompatActivity {


    @Override


    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);


        // 初始化蓝牙串口通信


        BluetoothSerial bluetoothSerial = new BluetoothSerial(this);


        // 其他初始化操作


    }


}

启动文件介绍

MainActivity.java: 应用程序的主活动,负责初始化界面和蓝牙串口通信。
onCreate(): 活动创建时调用的方法,设置布局文件并初始化蓝牙串口通信。

3. 项目的配置文件介绍

AndroidManifest.xml




<manifest xmlns:android="http://schemas.android.com/apk/res/android"


    package="com.harryjph.bluetoothserial">


 


    <application


        android:allowBackup="true"


        android:icon="@mipmap/ic_launcher"


        android:label="@string/app_name"


        android:roundIcon="@mipmap/ic_launcher_round"


        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>


 


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


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


    <uses-permission android:name="android.permission.




android-bluetooth-serialA library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.项目地址:https://gitcode.com/gh_mirrors/an/android-bluetooth-serial

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...