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>

最新文章

  1. 原生js+css3实现图片自动切换,图片轮播
  2. 深入浅出设计模式——策略模式(Strategy Pattern)
  3. 今天的感悟,对于python中的list()与w3c教程
  4. 使用fastcgi_finish_request提高页面响应速度
  5. sencha touch之store
  6. 软件工程随堂小作业—— 寻找“水王”(C++)
  7. baseadapter.getItemId的使用方法:实现listview筛选、动态删除
  8. CCS5 建立SYS/BIOS工程时报错“cannot find file &quot;./configPkg/linker.cmd&quot; bios”的解决方法
  9. LLVM在静态分析上的增强 @ WWDC 2013
  10. 畅通工程续 HDOJ--1874
  11. js中的隐式转换
  12. Netty事件监听和处理(下)
  13. Navicat for MySQL破解版安装
  14. Django之分页
  15. mysql 和 hive 和分布式zookeeper和HBASE分布式安装教程
  16. 安装PyQt5时缺少designer.exe的解决办法
  17. Kubernetes 基于 Metrics Server 与 HPA 的使用
  18. 阅读OReilly.Web.Scraping.with.Python.2015.6笔记---BeautifulSoup---findAll
  19. apache目录别名
  20. Docker(十一)-Docker commit创建镜像

热门文章

  1. SpringBoot 2.x (9):整合Mybatis注解实战
  2. Java基础50题test1—不死神兔
  3. MFC程序添加快捷键
  4. LookAround开元之旅(持续更新中...)
  5. 修改nagios登录界面密码
  6. Jsoup获取全国地区数据(省市县镇村)(续) 纯干货分享
  7. Openjudge 1.13-21:最大质因子序列
  8. php接口开发注意事项
  9. 与调试器共舞 - LLDB 的华尔兹
  10. 多源最短路径floyd