资源简介
最简单、功能最全的蓝牙类,只需要继承蓝牙activity实现接口即可。让蓝牙开发变得简单高效。
代码片段和文件信息
package com.mypeam.cjwddz.mpeam;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;
/**
* Created by cjwddz on 2016/8/21.
*/
public abstract class BleActivity extends Activity{
public static BluetoothAdapter bleadt =BluetoothAdapter.getDefaultAdapter();
private static final UUID PRIVATE_UUID = UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB“);
private static BluetoothSocket socket=null;
private static InputStream in=null;
private static OutputStream out=null;
BroadcastReceiver blebroadcast=new BroadcastReceiver() {
@Override
public void onReceive(Context context Intent intent) {
switch (intent.getAction()){
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
finishSearch();
break;
case BluetoothDevice.ACTION_ACL_CONNECTED:
connectedSuccess();
break;
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
lostconnect();
break;
case BluetoothDevice.ACTION_FOUND:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
deviceFound(device);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bleadt =BluetoothAdapter.getDefaultAdapter();
IntentFilter filter=new IntentFilter();
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
registerReceiver(blebroadcastfilter);
if(islinking())
reciveThread();
}
@Override
protected void onDestroy() {
unregisterReceiver(blebroadcast);
close();
super.onDestroy();
}
public abstract void finishSearch();
public abstract void connectedSuccess();
public abstract void lostconnect();
public abstract void deviceFound(BluetoothDevice device);
public abstract void connectFailed();
public abstract void bleMsg(byte[] msg);
//打开蓝牙
public void enableBle(boolean force)
{
if(!bleadt.isEnabled())
{
if(force)
bleadt.enable();
else
{
Intent enabler = new I
- 上一篇:jsp做的留言管理系统
- 下一篇:Java+OpenCV+OCR 图像字符处理
相关资源
- Android蓝牙和Cors网络开发源码
- Android蓝牙遥控器字符串形式应用例程
- Android蓝牙智能小车APP
- Android蓝牙设备之间通过UUID通信
- android蓝牙4.0(BLE)开发之ibeacon初步
- android蓝牙接收单片机数据并绘制波形
- android蓝牙apk控制蓝牙小车
- Arduino 蓝牙串口模块与Android蓝牙通信
- Android蓝牙开发客户端代码
- Android蓝牙socket应用编程-心电图-动态
- 基于Android蓝牙的遥控智能空调应用研
- android蓝牙4.0透传功能
- Android蓝牙无线对讲demo手机连接蓝牙耳
- Android蓝牙无线对讲demo手机连接蓝牙耳
- android蓝牙串口曲线显示
- Android蓝牙搜索自动配对通信Demo
- Android蓝牙录音
- Android蓝牙串口通讯直接能用
- Android蓝牙连接设备demo
- Android蓝牙扫描
- 目前一款可用的android蓝牙通信DEMO
- Android蓝牙开发搜索,配对,连接,数
- Android蓝牙demo142636
- Android蓝牙开发搜索、配对设备、蓝牙
- android蓝牙通信分为客户端,服务端
- Android蓝牙串口调试助手 蓝牙通信 透
- android蓝牙串口编程官方指导非常详细
- Android蓝牙操作源代码
- Android蓝牙2.0代码
- Android蓝牙串口传输心电数据画图的小
评论
共有 条评论