- 浏览: 79831 次
- 性别:
- 来自: 广州
最新评论
-
Tony_Lee-S:
已经说得很明白了吧?“把list强转成Serializable ...
在android中用 Intent 传递 List类型的数据(转) -
zhiduo5:
Activity与Service之间传递参数的介质这个怎么弄啊 ...
在android中用 Intent 传递 List类型的数据(转) -
mathlove:
很有用的内容
一个Android下的自动下载歌词的代码(转)
一. 修改本机蓝牙设备的可见性
二. 扫描周围可用的蓝牙设备
Eg:
一. 清单文件AdroidManifest.xml:
二. 布局文件: main.xml:
三. MainActivity:
转自:
http://blog.csdn.net/t12x3456/article/details/7865690
二. 扫描周围可用的蓝牙设备
Eg:
一. 清单文件AdroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.se7en" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <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"/> </manifest>
二. 布局文件: main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/discoverButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="设置可见性"/> <Button android:id="@+id/scanButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="开始扫描"/> </LinearLayout>
三. MainActivity:
import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button discoverButton = null; private Button scanButton = null; private BluetoothAdapter adapter = null; private BluetoothReceiver bluetoothReceiver = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); adapter = BluetoothAdapter.getDefaultAdapter(); discoverButton = (Button)findViewById(R.id.discoverButton); scanButton = (Button)findViewById(R.id.scanButton); //修改蓝牙设备的可见性 discoverButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View view) { Intent discoverIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); //设置蓝牙可见性,500表示可见时间(单位:秒),当值大于300时默认为300 discoverIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,500); startActivity(discoverIntent); } }); scanButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { //开始扫描周围蓝牙设备,该方法是异步调用并以广播的机制返回,所以需要创建一个BroadcastReceiver来获取信息 adapter.startDiscovery(); } }); //设定广播接收的filter IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); //创建蓝牙广播信息的receiver bluetoothReceiver = new BluetoothReceiver (); //注册广播接收器 registerReceiver(bluetoothReceiver,intentFilter); } private class BluetoothReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { //获得扫描到的远程蓝牙设备 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); System.out.println(device.getAddress()); } } }
转自:
http://blog.csdn.net/t12x3456/article/details/7865690
发表评论
-
SQLite多线程读写实践及常见问题总结(转)
2013-02-07 11:04 2969基本操作的部分,大家都很熟悉了,这里根据个人切身经验,总结了 ... -
android内存溢出的解决方法(转)
2013-02-07 11:23 7681. 当项目中包含大量图片,或者图片过大 方法1:等比例缩 ... -
android中的跨进程通信的实现——远程调用过程和aidl(转)
2013-02-07 19:35 1304android在设计理念上强调组件化,组件之间的依赖性很小。 ... -
在EditText/TextView中插入表情图片、样式、下划线等(转)
2012-08-22 12:01 1564EditText: 通常用于显示文字,但有时候也需要在文字中 ... -
自定义Tab选项卡(转)
2012-08-21 08:44 1458效果: 代码: import android.app. ... -
android设置button透明度(转)
2012-08-18 22:09 1200Button或者ImageButton的背景设为透明或者半透明 ... -
Android中的TabHost(转)
2012-08-17 14:50 2180介绍 有时,我们想在一个window中显示多个视图,这时就需 ... -
Android开发之蓝牙(Bluetooth)操作(一)--扫描已经配对的蓝牙设备(转)
2012-08-15 16:49 1655一. 什么是蓝牙(Bluetooth)? 1.1 BuleT ... -
一个Android下的自动下载歌词的代码(转)
2012-08-15 13:41 11071. 原理是用Baidu音乐搜索的连接,拼参数进去读取歌词。 ... -
ViewPager多页面滑动切换以及动画效果(转)
2012-08-14 16:55 1850一、首先,我们来看一下效果图,这是新浪微博的Tab滑动效果。我 ... -
Android的Handler总结(转)
2012-08-14 14:18 838一、Handler的定义: 主要接受子线程 ... -
AsyncTask的用法(转)
2012-08-14 14:11 867在开发Android应用时必须遵守单线程模型的原则: Andr ... -
Android逐帧动画(转)
2012-08-13 16:46 1750Android有两种动画,一种是tweened animati ... -
android 扫描SD卡与系统文件(转)
2012-08-11 16:12 1276当手机或模拟器开机时,会调用android的MediaScan ... -
android 怎样为多媒体文件生成缩略图(转)
2012-08-10 17:11 12151、Video 对于视频,取第一帧作为缩略图,也就是怎样从fi ... -
TextView 实现自动换行(转)
2012-08-10 16:44 1363package com.liao.intentservice; ... -
android:屏幕自适应(转)
2012-08-10 16:10 1367demo下载: http://www.eoeandroid.c ... -
listview加载性能优化ViewHolder (转)
2012-07-28 15:16 1423在android开发中Listview是一个很重要的组件,它以 ... -
android 应用程序Activity之间数据传递与共享的几种途径(转)
2012-07-19 11:03 14751.基于消息的通信机制 Intent ---boudle , ... -
Android进程间通信--消息机制及IPC机制实现(转)
2012-07-19 10:51 801一、概念及说明 Android ...
相关推荐
Android蓝牙开发框架! !
基于Android的BlueTooth开发手机蓝牙和蓝牙模块通讯,
可直接在HBuilderX 上运行,亲测可用。实现蓝牙状态实时监控,数据的接收和发送。外加Android原生蓝牙实现源码 + 串口调试工具
二 Android Bluetooth架构 2.1 Bluetooth架构图 2.2 Bluetooth 代码层次结构 三 Bluetooth 协议栈分析 3.1 蓝牙协议栈 3.2 Android 与蓝牙协议栈的Bluetooth 之HCI层分析 .4.1HCI层与基带的通信方 4.2包的分析及研究...
实现了Android三种蓝牙扫描方法。分别是注册蓝牙扫描广播,LeScanCallback和ScanCallback回调。
通过Android开发实现手机间通过蓝牙传输文件 实验小作业,详细分析 安卓平台提供对蓝牙的通讯栈的支持,允许设备和其他的设备进行无线传输数据。应用程序层通过安卓API来调用蓝牙的相关功能,这些API使程序无线连接...
delphi-android-bluetooth-printer-sample-master
Android-5.0-Bluetooth-HCI-Reqs
蓝牙协议栈bluetooth-src 蓝牙协议栈bluetooth-src
Android 蓝牙相关小Demo,实现的功能是点击按钮自动打开蓝牙并打印周边蓝牙设备。 (针对android 6.0以下) 文件上部是 MainActivity 的,下部是对应的布局文件。直接粘过去运行就可以了。 权限加一下: <uses-...
该用例是AndroidBLE蓝牙连接小设备的搜索,连接以及读取的相关用例。 如果还不对BLEandroid蓝牙的认识以及API有相关的认识:,那么请访问我的博客: http://blog.csdn.net/androidstarjack/article/details/60468468...
此应用程序支持不同的蓝牙设备: Bluetooth Classic(实施标准蓝牙SPP配置文件): – HC-05,HC-06,…… – Raspberry Pi 3 – …… 蓝牙LE(实施供应商特定的蓝牙GATT服务): – 预定义: * Nordic Semic
Android 蓝牙低功耗ble 广播、扫描、连接、数据读写源码流程图,非常详细的从btif-bta-btm-hci 数据流程走向,以及从controller收到数据到btm层,将Android 源码使用流程图的形式画了出来,使Android 蓝牙开发者更...
Android-Simple-Bluetooth-Example Simple Android Bluetooth example to turn on/off radio and to view and connect with devices. Has associated code to connect to an Arduino. For a complete tutorial write...
支持RCSP协议的固件,支持以下系列芯片 | AC693X, AC697X, AC695X等等 |最后列新... |- 杰理OTA外接库(Android)开发文档 --- 在线开发文档 |- 杰理之家SDK(Android)开发文档 --- 在线开发文档 |- libs -- 核心库<br
Android BLE 蓝牙开发框架,使用回调方式处理,搜索、连接、notify、indicate、读、写等一系列蓝牙操作
最新版Unity蓝牙插件 Bluetooth LE for iOS tvOS and Android 2.55
Android手机可以使用Bluetooth Low Engery或Bluetooth Classic同时与多个蓝牙设备进行通信。 蓝牙经典此代码旨在使用三种服务与三种蓝牙经典设备进行通信。 MyService1.java和MyService2.java与三个蓝牙设备有关。 ...
C++实现蓝牙bluetooth通讯功能,基础功能实现,源代码,