Sorted out all the sample apk and source code downloads and videos of Android Bluetooth 2.0SSP and 4.0 BLE. The video guarantees that it can send and receive hexadecimal or characters. It can automatically connect to the paired device and communicate with the serial port module . 100 copies of the unpublished source code.
Note: 20190507 about the cause and solution of the Bluetooth SSP2.0 device module cannot be found in android 6.0 and subsequent systems
Before version 6.0, to use the Bluetooth function, you only need to configure the following permissions:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
6.0 and later versions, using Bluetooth scanning, you also need to add the following permissions, and the permissions need to be dynamically applied during use:
<!-- Only needed for Android 6.0 Bluetooth scan -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
or
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
So to use the Bluetooth SSP2.0 device module, a total of 3 permissions are required:
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
(Do not refuse when the APP prompts permission to open Bluetooth and positioning permissions)
1. Bluetooth 2.0SSP example: (corresponding hardware module: Huicheng HC-05 and other chip CSR BC)
Recommendations: 1.Android Bluetooth 2.0 serial port assistant, send and receive hexadecimal/character automatic connection apk link: https://pan.baidu.com/s/1wD6t2-yOFET5GE9BaWA-2w Extract code: y7gu
2. BluetoothChat mobile phone and serial port module communication is close to automatic connection 2.0apk example: link: https://pan.baidu.com/s/1MEdcT-ImcveYytu8Mb79DQ
extraction code: flk4
3. Control car with voice can customize instructions and button names: link: http://pan.baidu.com/s/1nuEeFVV Password: 16uq
4. BluetoothChat mobile phone and mobile phone mobile phone and serial port module communication example: http://pan.baidu.com/s/1dDTZdJj
5. Industrial control application ISwitch13 jscw customization-lite version-5.0 tire pressure detection OK.apk link: http://pan.baidu.com/s/1c1IRNpQ password: k58x
Receive a byte between 0-60
6. Intelligent thermometer apk: link: http://pan.baidu.com/s/1hsybiuC Password: g85c
通过蓝牙接收,能记录31天的温度,并给出医学健康建议。蓝牙自动连接。
数据格式 比如36.98度对应十六进制03 06 09 08 固定为四个字节
7. The latest water drilling rig project Bluetooth comprehensive application Link: https://pan.baidu.com/s/1WJ2G-7rY2Thj6o_0bsymRw Extraction code: 55ak
IOS example: appstore download
2. Bluetooth 4.0 BLE example: (corresponding hardware module: CC2541/CC2540 Shenzhen Boluk BLE CC41, Huicheng HC-08 Bluetooth module, etc. JDY-30/31/32)
Recommendations: 1. android Bluetooth 4.0BLE serial port assistant can send and receive hexadecimal or characters without password, no need to pair with apk http://pan.baidu.com/s/1o8i5Iie
Bluetooth car remote control automatically connects with learning function with password ble4.0 Link: https://pan.baidu.com/s/1bLv1OM Password: f3tr
(Initial password 123456)
2. Official source link of Boluke: http://pan.baidu.com/s/1c2No4A8 Password: cbje
3.AMOMCU http://pan.baidu.com/s/1boiqyzP
4.AmoMcu-0.2 Simplified OK link: http://pan.baidu.com/s/1mhUMJw8 Password: 4pap
5.AmoMcu-Custom name and command version Universal version Link: http://pan.baidu.com/s/1dEZeKTj Password: 2pnb
6.PO141103045 Shenzhen Boluke BLE CC41 BluetoothLeGatt.apk http://pan.baidu.com/s/1o70QIO6
7. Industrial control application (video demonstration of Android Bluetooth serial industrial control software- Xiaohuangren software http://v.youku.com/v_show/id_XNzAwMTgxNzY0.html?from=y1.7-1.2) sample apk: http:// pan.baidu.com/s/1beoIia
IOS example: appstore download
JDY-30/31/32 dual-mode mode, both are supported.
3. Android OTG to serial USB to serial port (hardware: USB to serial cable corresponding to FT232, cp2102 chip)
Link: https://pan.baidu.com/s/1jI999Im Password: zjks (USB to serial cable corresponding to FT232 cp2102 chip)
OTG can send and receive characters, open and close the port baud rate setting, etc.
Link: https://pan.baidu.com/s/1kVkT98j Password: uvg7 (corresponding to CH34x, CH340 chip USB to serial cable)
Four, android serial port serial to serial port (hardware: serial cable and device directly connected)
Link: https://pan.baidu.com/s/1pL1Gult Password: 5wev
Five, android WIFI serial assistant (hardware: HC-22, Esp8266) LAN
Link: https://pan.baidu.com/s/1g3-BfBHngVuWeqRUbiMO8w Extraction code: 81al
package com.example.fileread2;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import android.support.v7.app.ActionBarActivity;
import android.text.format.Time;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
save("12\r\n1234");
Button btnLine=(Button)findViewById(R.id.button1);
Button btnAll=(Button)findViewById(R.id.button2);
final TextView dis = (TextView) findViewById(R.id.tv); // 得到数据显示句柄
btnLine.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dis.setText(readFirstLine());
}
});
btnAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dis.setText(readAll());
}
});
}
public void save(String filecontent) //位于/data/data/<package name>/files
{
//Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
//t.setToNow(); // 取得系统时间。
//String filename=String.format("%04d-%02d-%02d.txt", t.year,t.month+1,t.monthDay);
String filename="视力记录表.txt";
try {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File f2 = new File(Environment.getExternalStorageDirectory()+"/test/");
f2.mkdir();
//Toast.makeText(this,"卡"+f2.toString()+"/"+filename,Toast.LENGTH_SHORT).show();
//执行存储sdcard方法
File f = new File(f2,filename);
FileOutputStream out = new FileOutputStream(f,true);
out.write(filecontent.getBytes("UTF-8"));
}
else{
//存储到手机中,或提示
Toast.makeText(this,"无卡,保存到手机"+getFilesDir().toString()+"/"+filename,Toast.LENGTH_SHORT).show();
FileOutputStream outStream=this.openFileOutput(filename,Context.MODE_APPEND); //模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件。
outStream.write(filecontent.getBytes("UTF-8"));
outStream.close();
}
} catch (FileNotFoundException e) {
return;
}
catch (IOException e){
return ;
}
}
public String readAll()
{
StringBuffer sb = new StringBuffer();
String filename="test.txt";
try {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File f2 = new File(Environment.getExternalStorageDirectory()+"/test/");
File f = new File(f2,filename);
BufferedReader br = new BufferedReader(new FileReader(f));
String readline = "";
while ((readline = br.readLine()) != null) {
// System.out.println("readline:" + readline);
Log.d("chenhao", "chenhao"+"readline:" + readline);
sb.append(readline);
}
br.close();
}
else{
//存储到手机中,或提示
Toast.makeText(this,"无卡"+getFilesDir().toString()+"/"+filename,Toast.LENGTH_SHORT).show();
}
} catch (FileNotFoundException e) {
return "";
}
catch (IOException e){
return "";
}
return "读取成功:" + sb.toString();
}
public String readFirstLine()
{
StringBuffer sb = new StringBuffer();
String filename="test.txt";
try {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File f2 = new File(Environment.getExternalStorageDirectory()+"/test/");
File f = new File(f2,filename);
BufferedReader br = new BufferedReader(new FileReader(f));
String readline = "";
readline = br.readLine();
// while ((readline = br.readLine()) != null) {
// System.out.println("readline:" + readline);
Log.d("chenhao", "chenhao"+"readline:" + readline);
sb.append(readline);
// }
br.close();
}
else{
//存储到手机中,或提示
Toast.makeText(this,"无卡"+getFilesDir().toString()+"/"+filename,Toast.LENGTH_SHORT).show();
}
} catch (FileNotFoundException e) {
return "没有找到文件";
}
catch (IOException e){
return "IO异常";
}
return "首行读取成功:" + sb.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* 判断SDCard是否存在 [当没有外挂SD卡时,内置ROM也被识别为存在sd卡]
*
* @return
*/
public static boolean isSdCardExist() {
return Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);
}
/**
* 获取SD卡根目录路径
*
* @return
*/
public static String getSdCardPath() {
boolean exist = isSdCardExist();
String sdpath = "";
if (exist) {
sdpath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
} else {
sdpath = "不适用";
}
return sdpath;
}
/**
* 获取默认的文件路径
*
* @return
*/
public static String getDefaultFilePath() {
String filepath = "";
File file = new File(Environment.getExternalStorageDirectory(),
"test.txt");
if (file.exists()) {
filepath = file.getAbsolutePath();
} else {
filepath = "不适用";
}
return filepath;
}
/*
public void readFileFS() //使用FileInputStream读取文件
{
try {
File file = new File(Environment.getExternalStorageDirectory(),
"test.txt");
FileInputStream is = new FileInputStream(file);
byte[] b = new byte[is.available()];
is.read(b);
String result = new String(b);
System.out.println("读取成功:"+result);
} catch (Exception e) {
e.printStackTrace();
}
}
*/
public void readFileBR() //使用BufferReader读取文件
{
try {
File file = new File(Environment.getExternalStorageDirectory(),
"test.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String readline = "";
StringBuffer sb = new StringBuffer();
while ((readline = br.readLine()) != null) {
System.out.println("readline:" + readline);
sb.append(readline);
}
br.close();
System.out.println("读取成功:" + sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Xiaohuangren Software Taobao Flagship Store
Program source code, customized expert phone: 18910620895 Want: chenhao0568 QQ: 345139427