[uiautomator篇] bluetooth---接口来做
package com.softwinner.performance.frameratetest; import android.Manifest;
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.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast; import java.util.Set; public class MainActivity extends AppCompatActivity { private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
private String mLogTag = "bluetoothtest";
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action)){
BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.i(mLogTag,remoteDevice.getName() + " address: " + remoteDevice.getAddress());
}
else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
Log.i(mLogTag,"search finished");
} }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.KILL_BACKGROUND_PROCESSES) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.KILL_BACKGROUND_PROCESSES},);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},);
}
searchDevices(); } private void searchDevices(){ if(mBluetoothAdapter == null){
Log.i(mLogTag,"device not support bluetooth");
Toast.makeText(MainActivity.this,"device not support bluetooth",Toast.LENGTH_SHORT).show();
return;
}
if(!mBluetoothAdapter.isEnabled()){
mBluetoothAdapter.enable();
mBluetoothAdapter.cancelDiscovery();
Toast.makeText(MainActivity.this,"bluetooth has open",Toast.LENGTH_SHORT).show();
} IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.setPriority(Integer.MAX_VALUE);
registerReceiver(mReceiver,filter); mBluetoothAdapter.startDiscovery();
try {Thread.sleep();} catch (InterruptedException e) {e.printStackTrace();}
// showBoundDevices(); }
private void showBoundDevices(){
// List<Map<String, String>> mBoundDevicesList = new ArrayList<>();
Set<BluetoothDevice> pairDevices = mBluetoothAdapter.getBondedDevices();
if(pairDevices.size() > ){
for(BluetoothDevice boundDevice : pairDevices){
System.out.println(boundDevice.getName() + " " + boundDevice.getAddress());
Log.i(mLogTag, boundDevice.getName()+ " " + boundDevice.getAddress());
}
} } }
主要的是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.softwinner.performance.frameratetest">
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.softwinner.performance.frameratetest.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
[uiautomator篇] bluetooth---接口来做的更多相关文章
- 持续集成之单元测试篇——WWH(讲讲我们做单元测试的故事)
持续集成之单元测试篇--WWH(讲讲我们做单元测试的故事) 前言 临近上线的几天内非重大bug不敢进行发版修复,担心引起其它问题(摁下葫芦浮起瓢) 尽管我们如此小心,仍不能避免修改一些bug而引起更多 ...
- 如何起草你的第一篇科研论文——应该做&避免做
如何起草你的第一篇科研论文——应该做&避免做 导语:1.本文是由Angel Borja博士所写.本文的原文链接在这里.感谢励德爱思唯尔科技的转载,和刘成林老师的转发.2.由于我第二次翻译,囿于 ...
- [android 应用框架api篇] bluetooth
bluetooth接口 android.bluetooth.jar 官网网址: 接口类: https://developer.android.com/reference/android/bluetoo ...
- [automator学习篇]android 接口-- bluetooth
http://www.android-doc.com/guide/topics/connectivity/bluetooth.html 本地下载的sdk 目录: D:\AndroidSdk\s ...
- [uiautomator篇][python] wifi接口学习网址
https://wifi.readthedocs.io/en/latest/wifi_command.html#usage
- .NET Core CSharp初级篇 1-5 接口、枚举、抽象
.NET Core CSharp初级篇 1-5 本节内容类的接口.枚举.抽象 简介 问题 如果你需要表示星期或者是某些状态,使用字符串或者数字是否不直观? 你是否发现,无论何种电脑,它的USB口的设计 ...
- 第二十一篇:spring怎么做缓存
项目背景:你可能遇情景:1.一个做统计的页面,每次刷新需要调接口做查询 ,是联表查询,查出来的数据还需要做一些计算或者加工,不算页面上的图表插件,刷新一次,延迟个几秒钟才出的来2. 一个统计接口如此 ...
- webservice第三篇【接口开发webservice、CXF框架使用、IDEA下使用webservice、小例子】
实现接口的webservice 服务端 import javax.jws.WebService; /**面向接口的webservice发布方式 * * */ @WebService public in ...
- Asp.Net Core 使用Quartz基于界面画接口管理做定时任务
今天抽出一点点时间来造一个小轮子,是关于定时任务这块的. 这篇文章主要从一下几点介绍: 创建数据库管理表 创建web项目 引入quarzt nuget 包 写具体配置操作,实现定时任务处理 第一步:创 ...
随机推荐
- 装饰者模式--Java篇
装饰者模式(Decorator):动态地给一个对象添加一些额外的职责,就增加功能来说,装饰者模式比生成子类更为灵活. 1.定义接口,可以动态的给对象添加职责. package com.lujie; p ...
- jQuery事件,对象以及插件
回顾 1 基本使用 2 jquery 选择器 3 筛选器 过滤 查找 串联 4 DOM 操作 内部插入 append()appendTo()prepend()prependTo() 外部插入 afte ...
- Android中的ListView属性使用总结
Android中使用ListView控件比较常见,如果能知道常用的一些属性使用,肯定会少很多坑. 1.ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景 ...
- run_test() 验证平台的入口
Run,just run! ——阿甘正传 一个简单的例子: module tb_top; dut u_dut (); initial begin run_test(); end config ...
- MySQL select * 和把所有的字段都列出来,哪个效率更高?
MySQL select * 和把所有的字段都列出来,哪个效率更高 答案是:如何,都不推荐使用 SELECT * FROM (1)SELECT *,需要数据库先 Query Table Metadat ...
- UVA 1412 Fund Management (预处理+状压dp)
状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...
- Swift REPL入门介绍
Xcode 6.1 引入了一个新特性用来辅助Swift开发,即Read Eval Print Loop(“读取-求值-输出”循环,简称REPL).熟悉解释型语言的开发者将会对这个命令行环境感到舒适,而 ...
- WPF中窗体调用窗体
在WPF中有时候我们需要在一个窗体中去调用另外的一个窗体,下面给出调用方法. 下面实现在MainWindow中通过点击一个按钮调用另外的一个窗口. 首先创建你要调用的另外一个窗口:点击最上面的项目 ...
- cdlinux
xset q xset s 6000 xset -dpms ntpdate time.nist.gov date
- syslog(),closelog()与openlog()--日志操作函数 (1)
文章出处:http://blog.csdn.net/xx77009833/archive/2010/07/30/5776383.aspx 为了满足某些目的,进行日志记录是很有必要的. 在典型的 LIN ...